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

Project 2: Rony Edde #18

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
668 changes: 666 additions & 2 deletions README.md

Large diffs are not rendered by default.

Binary file added images/bench1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bench2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bench_GPU_functions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/bottleneck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/memoryswapping.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
374 changes: 372 additions & 2 deletions src/main.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions stream_compaction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set(SOURCE_FILES
"efficient.cu"
"thrust.h"
"thrust.cu"
"radix.h"
"radix.cu"
)

cuda_add_library(stream_compaction
Expand Down
12 changes: 12 additions & 0 deletions stream_compaction/common.cu
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ namespace Common {
*/
__global__ void kernMapToBoolean(int n, int *bools, const int *idata) {
// TODO
int index = (blockIdx.x * blockDim.x) + threadIdx.x;
if (index >= n)
return;

bools[index] = idata[index] != 0;

}

/**
Expand All @@ -33,6 +39,12 @@ __global__ void kernMapToBoolean(int n, int *bools, const int *idata) {
__global__ void kernScatter(int n, int *odata,
const int *idata, const int *bools, const int *indices) {
// TODO
int index = (blockIdx.x * blockDim.x) + threadIdx.x;
if (index >= n)
return;

if (bools[index] == 1)
odata[indices[index]] = idata[index];
}

}
Expand Down
67 changes: 64 additions & 3 deletions stream_compaction/cpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ namespace CPU {
*/
void scan(int n, int *odata, const int *idata) {
// TODO
printf("TODO\n");
//printf("TODO\n");
odata[0] = 0;
for (int i = 1; i < n; i++)
{
odata[i] = odata[i-1] + idata[i-1];
}
}

/**
Expand All @@ -19,7 +24,18 @@ void scan(int n, int *odata, const int *idata) {
*/
int compactWithoutScan(int n, int *odata, const int *idata) {
// TODO
return -1;
int count = 0;
odata[0] = 0;

for (int i = 0; i < n; i++)
{
if (idata[i] != 0)
{
odata[count] = idata[i];
count++;
}
}
return count;
}

/**
Expand All @@ -29,7 +45,52 @@ int compactWithoutScan(int n, int *odata, const int *idata) {
*/
int compactWithScan(int n, int *odata, const int *idata) {
// TODO
return -1;
//return -1;

int* mapdata = new int[n];
int* scandata = new int[n];

memset(mapdata, 0, n*sizeof(int));
memset(scandata, 0, n*sizeof(int));


for (int i = 0; i < n; i++)
{
if (idata[i] != 0)
mapdata[i] = 1;
}

scan(n, scandata, mapdata);

int count = 0;
for (int i = 0; i < n; i++)
{
//odata[count] = mapdata[i] * idata[scandata[i]];
//count += mapdata[i];
if (mapdata[i] != 0)
{
odata[scandata[i]] = idata[i];
}
}
count = scandata[n - 1] + mapdata[n-1];

/*
printf("\n%-10s", "idata: "); for (int i = 0; i < 20; i++)
printf("%d ", idata[i]);
printf("\n%-10s", "mapdata: "); for (int i = 0; i < 20; i++)
printf("%d ", mapdata[i]);
printf("\n%-10s", "scandata: "); for (int i = 0; i < 20; i++)
printf("%d ", scandata[i]);
printf("\n%-10s", "odata: "); for (int i = 0; i < 20; i++)
printf("%d ", odata[i]);
printf("\n");
*/

delete[] mapdata;
delete[] scandata;

return count;

}

}
Expand Down
Loading