Skip to content
Snippets Groups Projects
Commit dfda85df authored by Andreas Herten's avatar Andreas Herten
Browse files

Add CUDA macro, add Makefile and syncfile

parent c061b443
No related branches found
No related tags found
No related merge requests found
# This file steers synchronization of the current folder with different target machines
# See https://github.com/AndiH/simpler-rsync for more information
[juhydra]
hostname = "juhydra"
target_folder = "~/TMP/CUDA-Hello-World/"
[juron]
hostname = "juron"
target_folder = "~/TMP/JURON/CUDA-Hello-World"
default = true
Makefile 0 → 100644
NVCC=nvcc
hello-world: hello-world.cu Makefile
$(NVCC) -o hello-world hello-world.cu
.PHONY: clean run
clean:
rm hello-world
run: hello-world
bsub -R "rusage[ngpus_shared=20]" -I ./hello-world
...@@ -6,6 +6,23 @@ ...@@ -6,6 +6,23 @@
// nvcc hello-world.cu -L /usr/local/cuda/lib -lcudart -o hello-world // nvcc hello-world.cu -L /usr/local/cuda/lib -lcudart -o hello-world
//Macro for checking cuda errors
// #define CUDA_CALL(call) { \
// cudaError_t e = call; \
// if(e != cudaSuccess) { \
// printf("Cuda failure %s:%d: '%s' in %s\n", __FILE__, __LINE__, cudaGetErrorString(e), #call); \
// exit(0); \
// } \
// }
#include <iostream>
#define CUDA_CALL( call ) \
{ \
cudaError_t result = call; \
if ( cudaSuccess != result ) \
std::cerr << "CUDA error " << result << " in " << __FILE__ << ":" << __LINE__ << ": " << cudaGetErrorString( result ) << " (" << #call << ")" << std::endl; \
}
#include <stdio.h> #include <stdio.h>
const int N = 16; const int N = 16;
...@@ -29,17 +46,17 @@ int main() ...@@ -29,17 +46,17 @@ int main()
printf("%s", a); printf("%s", a);
cudaMalloc( (void**)&ad, csize ); CUDA_CALL(cudaMalloc( (void**)&ad, csize );)
cudaMalloc( (void**)&bd, isize ); CUDA_CALL(cudaMalloc( (void**)&bd, isize );)
cudaMemcpy( ad, a, csize, cudaMemcpyHostToDevice ); CUDA_CALL(cudaMemcpy( ad, a, csize, cudaMemcpyHostToDevice );)
cudaMemcpy( bd, b, isize, cudaMemcpyHostToDevice ); CUDA_CALL(cudaMemcpy( bd, b, isize, cudaMemcpyHostToDevice );)
dim3 dimBlock( blocksize, 1 ); dim3 dimBlock( blocksize, 1 );
dim3 dimGrid( 1, 1 ); dim3 dimGrid( 1, 1 );
hello<<<dimGrid, dimBlock>>>(ad, bd); hello<<<dimGrid, dimBlock>>>(ad, bd);
cudaMemcpy( a, ad, csize, cudaMemcpyDeviceToHost ); CUDA_CALL(cudaMemcpy( a, ad, csize, cudaMemcpyDeviceToHost );)
cudaFree( ad ); CUDA_CALL(cudaFree( ad );)
cudaFree( bd ); CUDA_CALL(cudaFree( bd );)
printf("%s\n", a); printf("%s\n", a);
// sleep(1); // sleep(1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment