Skip to content

Commit

Permalink
new compare function
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonglin Chen committed Apr 23, 2019
1 parent 4a62156 commit f002aba
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
\.DS_Store
*.o
groupby
groupby-hash
groupby_hash
*~
37 changes: 34 additions & 3 deletions cpuGroupby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,19 +400,50 @@ void cpuGroupby::printGPUResults(int* GPU_output_keys, int* GPU_output_values){
std::cout << "End GPU Printing Results" << std::endl;
}

bool cpuGroupby::validGPUResult(int* GPUKeys, int* GPUValues, int GPUOutputRows) {
//ASSUMING THE GPU RESULT IS SORTED
bool cpuGroupby::validGPUResult(int* GPUKeys, int* GPUValues, int GPUOutputRows, bool isSorted) {
if (GPUOutputRows != numGroups) {
std::cout << "FAILED - CPU Rows: " << numGroups << " GPU Rows: " << GPUOutputRows << std::endl;
return false;
}

// cout << "GPU:CPU"<<endl;
for (int i=0; i<num_value_columns*numGroups; i++) {
if (isSorted) {
for (int i=0; i<num_value_columns*numGroups; i++) {
// cout << GPUValues[i] << ":" << output_values[i] << endl;
if (GPUValues[i] != output_values[i]) {
std::cout << "FAILED - CPU data != GPU data " << std::endl;
return false;
}
}
} else {
std::vector<size_t> idx(GPUOutputRows);
std::iota(idx.begin(), idx.end(), 0);
std::sort(idx.begin(), idx.end(),
[=] (const size_t idx1, const size_t idx2) {
for (size_t i = 0; i < num_key_columns; ++i) {
size_t data1 = GPUKeys[i * GPUOutputRows + idx1];
size_t data2 = GPUKeys[i * GPUOutputRows + idx2];
if (data1 > data2) return false;
if (data1 < data2) return true;
}
return false;
});
for (size_t i = 0; i < GPUOutputRows; ++i) {
for (size_t j = 0; j < num_key_columns; ++j) {
if (GPUKeys[j * GPUOutputRows + idx[i]] != output_keys[j * GPUOutputRows + i]) {
std::cout << "FAILED - CPU key != GPU key at entry " << i << std::endl;
return false;
}
}
}
for (size_t i = 0; i < GPUOutputRows; ++i) {
for (size_t j = 0; j < num_value_columns; ++j) {
if (GPUValues[j * GPUOutputRows + idx[i]] != output_values[j * GPUOutputRows + i]) {
std::cout << "FAILED - CPU data != GPU data at entry " << i << std::endl;
return false;
}
}
}
}
std::cout << "PASSED - CPU data == GPU data " << std::endl;
return true;
Expand Down
2 changes: 1 addition & 1 deletion cpuGroupby.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class cpuGroupby {
~cpuGroupby(); // To do - make sure arrays are freed

// GPU Validation
bool validGPUResult(int* GPUKeys, int* GPUValues, int GPUOutputRows);
bool validGPUResult(int* GPUKeys, int* GPUValues, int GPUOutputRows, bool isSorted=true);
};

#endif /* cpuGroupby_hpp */
1 change: 0 additions & 1 deletion groupby_hash_templates.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ bool keyEqualRM(T* key_columns, size_t idx1, size_t idx2, size_t num_key_rows, s

// hashKey generating
template <typename T> __host__ __device__
__host__ __device__
size_t HashKey(size_t idx, T* key_columns, size_t num_key_rows, size_t num_key_columns) {
size_t hash_key = 0;
for (size_t i=0; i < num_key_columns; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion main_hash.cu
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int main(int argc, const char * argv[]) {
std::cout << "CPU time: " << cpu_duration.count() << " s" << std::endl;
std::cout << "GPU time: " << gpu_duration.count() << " s" << std::endl;

slowGroupby.validGPUResult(gpu_output_keys, gpu_output_values, gpu_output_rows);
slowGroupby.validGPUResult(gpu_output_keys, gpu_output_values, gpu_output_rows, false);

cudaFreeHost(original_value_columns);
cudaFreeHost(original_key_columns);
Expand Down
1 change: 0 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Makefile for GPU GroupBy Project
# EE-5351 Fall 2018
dbg = 1
NVCC = nvcc
NVCC_FLAGS = -I/usr/local/cuda/include -gencode=arch=compute_60,code=\"sm_60\" --relocatable-device-code true
CXX_FLAGS = -std=c++11
Expand Down

0 comments on commit f002aba

Please sign in to comment.