Skip to content
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
90 changes: 84 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,90 @@ CUDA Stream Compaction

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 2**

* (TODO) YOUR NAME HERE
* (TODO) [LinkedIn](), [personal website](), [twitter](), etc.
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Xinyu Lin
[Linkedin](https://www.linkedin.com/in/xinyu-lin-138352125/)
* Tested on: Windows 10, Intel(R) Core(TM) i7-6700HQ [email protected], 16GB, GTX960M(Private Computer)

### (TODO: Your README)
### Features

Include analysis, etc. (Remember, this is public, so don't put
anything here that you don't want to share with the world.)
* CPU Scan & Stream Compaction
* Naive GPU Scan Algorithm
* Work-Efficient GPU Scan
* Work-Efficient GPU Stream Compaction
* Thrust Implementation

### Performance Analysis
* BlockSize over Scan methods(ArraySize: 256)
![](img/bsscan.png)

* BlockSize over Compact methods(ArraySize: 256)
![](img/bscompact.png)

* ArraySize over Scan methods(BlockSize: 512)
![](img/as256scan.png)
![](img/as512scan'.png)
![](img/as1024scan.png)

* ArraySize over Compact methods(BlockSize: 512)
![](img/as256compact.png)
![](img/as512compact.png)
![](img/as1024compact.png)

### Result
```
****************
** SCAN TESTS **
****************
[ 33 32 23 11 4 10 29 49 9 36 47 43 19 ... 20 0 ]
==== cpu scan, power-of-two ====
elapsed time: 0.001185ms (std::chrono Measured)
[ 0 33 65 88 99 103 113 142 191 200 236 283 326 ... 6332 6352 ]
==== cpu scan, non-power-of-two ====
elapsed time: 0.001185ms (std::chrono Measured)
[ 0 33 65 88 99 103 113 142 191 200 236 283 326 ... 6208 6251 ]
passed
==== naive scan, power-of-two ====
elapsed time: 0.240992ms (CUDA Measured)
passed
==== naive scan, non-power-of-two ====
elapsed time: 0.189888ms (CUDA Measured)
passed
==== work-efficient scan, power-of-two ====
elapsed time: 0.262976ms (CUDA Measured)
passed
==== work-efficient scan, non-power-of-two ====
elapsed time: 0.228768ms (CUDA Measured)
passed
==== thrust scan, power-of-two ====
elapsed time: 0.001088ms (CUDA Measured)
passed
==== thrust scan, non-power-of-two ====
elapsed time: 0.001088ms (CUDA Measured)
passed

*****************************
** STREAM COMPACTION TESTS **
*****************************
[ 1 0 2 2 0 2 3 2 0 0 3 1 0 ... 0 0 ]
==== cpu compact without scan, power-of-two ====
elapsed time: 0.001975ms (std::chrono Measured)
[ 1 2 2 2 3 2 3 1 3 2 1 2 1 ... 2 3 ]
passed
==== cpu compact without scan, non-power-of-two ====
elapsed time: 0.001976ms (std::chrono Measured)
[ 1 2 2 2 3 2 3 1 3 2 1 2 1 ... 2 3 ]
passed
==== cpu compact with scan ====
elapsed time: 0.008692ms (std::chrono Measured)
[ 1 2 2 2 3 2 3 1 3 2 1 2 1 ... 2 3 ]
passed
==== work-efficient compact, power-of-two ====
elapsed time: 0.499232ms (CUDA Measured)
passed
==== work-efficient compact, non-power-of-two ====
elapsed time: 0.43552ms (CUDA Measured)
passed
```



Binary file added img/as1024compact.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 img/as1024scan.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 img/as256compact.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 img/as256scan.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 img/as512compact.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 img/as512scan'.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 img/bscompact.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 img/bsscan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ int main(int argc, char* argv[]) {
StreamCompaction::Efficient::scan(NPOT, c, a);
printElapsedTime(StreamCompaction::Efficient::timer().getGpuElapsedTimeForPreviousOperation(), "(CUDA Measured)");
//printArray(NPOT, c, true);
//std::cout << "my result: "<< std::endl;
//for (int i = 0; i < SIZE; ++i)
//{
// std::cout << c[i] << " ";
//}
//std::cout << std::endl;
//std::cout << "correct result: " << std::endl;
//for (int i = 0; i < SIZE; ++i)
//{
// std::cout << b[i] << " ";
//}
printCmpResult(NPOT, b, c);

zeroArray(SIZE, c);
Expand Down
2 changes: 1 addition & 1 deletion stream_compaction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ set(SOURCE_FILES

cuda_add_library(stream_compaction
${SOURCE_FILES}
OPTIONS -arch=sm_20
OPTIONS -arch=sm_50
)
2 changes: 1 addition & 1 deletion stream_compaction/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, __LINE__)

#define blockSize 1024
/**
* Check for CUDA errors; print and exit if there was a problem.
*/
Expand Down
72 changes: 64 additions & 8 deletions stream_compaction/cpu.cu
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include <cstdio>
#include "cpu.h"

#include "common.h"
#include "common.h"

namespace StreamCompaction {
namespace CPU {
using StreamCompaction::Common::PerformanceTimer;
PerformanceTimer& timer()
{
static PerformanceTimer timer;
return timer;
using StreamCompaction::Common::PerformanceTimer;
PerformanceTimer& timer()
{
static PerformanceTimer timer;
return timer;
}

/**
Expand All @@ -20,6 +20,13 @@ namespace StreamCompaction {
void scan(int n, int *odata, const int *idata) {
timer().startCpuTimer();
// TODO
// Serial Scan: Exclusive
int acc = 0;
for (int i = 0; i < n; i++)
{
odata[i] = acc;
acc = acc + idata[i];
}
timer().endCpuTimer();
}

Expand All @@ -31,8 +38,19 @@ namespace StreamCompaction {
int compactWithoutScan(int n, int *odata, const int *idata) {
timer().startCpuTimer();
// TODO
int flag = 0;
for (int i = 0; i < n; ++i)
{
if (idata[i] != 0)
{
odata[flag] = idata[i];
flag++;
}

}

timer().endCpuTimer();
return -1;
return flag;
}

/**
Expand All @@ -43,8 +61,46 @@ namespace StreamCompaction {
int compactWithScan(int n, int *odata, const int *idata) {
timer().startCpuTimer();
// TODO
// predicate
int acc = 0;
int* tempdata = new int[n];
for (int i = 0; i < n; ++i)
{
if (idata[i] == 0)
{
tempdata[i] = 0;

}
else
{
tempdata[i] = 1;
acc++;
}
}
// ======= tempdata[] = 1110011111001111
// scan sum
int accSum = 0;
int* tempData2 = new int[n];
for (int i = 0; i < n; i++)
{
tempData2[i] = accSum;
accSum += tempdata[i];

}

// idata[] = 3120043215002222
// ======= tempdata[] = 1110011111001111
// tempData2[] = 0123334567899910....
// scatter
for (int i = 0; i < n; ++i)
{
odata[tempData2[i]] = idata[i];
}

delete[] tempdata;
delete[] tempData2;
timer().endCpuTimer();
return -1;
return acc;
}
}
}
Loading