Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homework4 #3

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update histo
ryan committed Nov 15, 2022
commit 83e9061873632ad93dd2808a7ce4f1bf06c8ce92
15 changes: 12 additions & 3 deletions hw4/hw4.cpp
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ __global__ void normalize(float min, float *out)
{
int tid = threadIdx.x + blockDim.x*blockIdx.x;
out[tid] -= min;
//divide max-min
//(int) *1023
}

__global__ void histogram_smem_atomics(const float *in, float range, float min, float *out)
@@ -40,11 +42,17 @@ __global__ void histogram_smem_atomics(const float *in, float range, float min,

__syncthreads();
//atomicAdd(&numThreads,1);

float value = in[t];
value = (int)((value-min)/(range))*1023;
//value /= binSize;
int bin = value;
int temp;
temp = (in[t]);
int buffer = temp % NUM_BINS;
atomicAdd(&smem[int(temp/binSize)], 1);
//atomicAdd(&smem[int(buffer)],1);
//atomicAdd(&smem[int(temp/binSize)], 1);
//atomicAdd(&out[bin], 1);
atomicAdd(&smem[bin],1);
//atomicAdd(&out[temp/binSize],1);

__syncthreads();
@@ -223,7 +231,7 @@ float MmmPi(int n)
hipMemcpy(&value, dReduc, sizeof(float), hipMemcpyDeviceToHost);
minValue = value;

normalize<<<gridDim,blockDim>>>(minValue,dData);
//normalize<<<gridDim,blockDim>>>(minValue,dData);


//Histo
@@ -259,6 +267,7 @@ float MmmPi(int n)
std::cout << "Serial sum: " << serialSum << std::endl;
std::cout << "Max: " << maxValue << std::endl;
std::cout << "Min: " << minValue << std::endl;
std::cout << "Math: " << (int)(1.880974126480706/((maxValue-minValue)/NUM_BINS)) << std::endl;

//Free memory
hipFree(dReduc);