forked from pmccormick/kitsune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9094d3
commit dbfc195
Showing
11 changed files
with
150 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
include ../experiments.mk | ||
|
||
targets += vecadd.cuda.${host_arch} | ||
|
||
VPATH := ./ | ||
|
||
forall_lto_src = vecadd-init.cpp vecadd-add.cpp vecadd-forall.cpp | ||
|
||
all: ${targets} | ||
|
||
############################# | ||
# cuda target | ||
# | ||
forall_cuda_lto_objs := $(patsubst %.cpp, %.cuda.lto.o, $(notdir $(forall_lto_src))) | ||
|
||
%.cuda.lto.o: %.cpp | ||
${KIT_CXX} -ftapir=cuda -c -flto -O1 -o $@ $< | ||
# ${KITSUNE_PREFIX}/bin/llvm-dis -o $@.ll $@ | ||
|
||
vecadd.cuda.${host_arch}: ${forall_cuda_lto_objs} | ||
${KIT_CXX} -flto -fuse-ld=lld -ftapir=cuda ${TAPIR_CUDA_LTO_FLAGS} -o $@ ${forall_cuda_lto_objs} \ | ||
-Xlinker -rpath=${KITSUNE_PREFIX}/lib | ||
cuobjdump -symbols $@ | ||
|
||
clean: | ||
-rm -f *.${host_arch} *.o *.lto.o | ||
-rm -f *.fatbin | ||
-rm -rf *-cfg-tmp | ||
-rm -f *.bc | ||
-rm -f *.fatbin | ||
-rm -f *.ppm *.jpg | ||
-rm -f *.ll *.ptx *.csv *.log *.s *.fbin *.tapir | ||
-rm -f *.dat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <cstdlib> | ||
#include <kitsune.h> | ||
|
||
extern "C" { | ||
void vec_add(const float *A, const float *B, float *C, uint64_t N) { | ||
forall(size_t i = 0; i < N; ++i) | ||
C[i] = A[i] + B[i]; | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <chrono> | ||
#include <kitsune.h> | ||
|
||
extern "C" void fill(float *data, uint64_t N); | ||
extern "C" void vec_add(const float *A, const float *B, float *C, uint64_t N); | ||
|
||
int main (int argc, char* argv[]) { | ||
using namespace std; | ||
uint64_t size = 1024 * 1024 * 256; | ||
unsigned int iterations = 10; | ||
cout << setprecision(5); | ||
cout << "\n"; | ||
cout << "---- vector addition benchmark (forall) ----\n" | ||
<< " Vector size: " << size << " elements.\n\n"; | ||
cout << " Allocating arrays and filling with random values..." | ||
<< std::flush; | ||
float *A = alloc<float>(size); | ||
float *B = alloc<float>(size); | ||
float *C = alloc<float>(size); | ||
fill(A, size); | ||
fill(B, size); | ||
cout << " done.\n\n"; | ||
|
||
double elapsed_time; | ||
double min_time = 100000.0; | ||
double max_time = 0.0; | ||
for(unsigned t = 0; t < iterations; t++) { | ||
auto start_time = chrono::steady_clock::now(); | ||
vec_add(A, B, C, size); | ||
auto end_time = chrono::steady_clock::now(); | ||
elapsed_time = chrono::duration<double>(end_time-start_time).count(); | ||
if (elapsed_time < min_time) | ||
min_time = elapsed_time; | ||
if (elapsed_time > max_time) | ||
max_time = elapsed_time; | ||
cout << "\t" << t << ". iteration time: " << elapsed_time << ".\n"; | ||
} | ||
cout << " Checking final result..." << std::flush; | ||
|
||
size_t error_count = 0; | ||
for(size_t i = 0; i < size; i++) { | ||
float sum = A[i] + B[i]; | ||
if (C[i] != sum) | ||
error_count++; | ||
} | ||
if (error_count) { | ||
cout << " incorrect result found! (" | ||
<< error_count << " errors found)\n\n"; | ||
return 1; | ||
} else { | ||
cout << " pass (answers match).\n\n" | ||
<< " Total time: " << elapsed_time | ||
<< " seconds. (" << size / elapsed_time << " elements/sec.)\n" | ||
<< "*** " << min_time << ", " << max_time << "\n" | ||
<< "----\n\n"; | ||
} | ||
|
||
return error_count; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <cstdlib> | ||
#include <kitsune.h> | ||
|
||
extern "C" { | ||
void fill(float *data, uint64_t N) { | ||
float base_value = rand() / (float)RAND_MAX; | ||
forall(size_t i = 0; i < N; ++i) | ||
data[i] = base_value + i; | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters