The source code and dockerfile for the GSW2024 AI Lab.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

59 lines
1.6 KiB

2 months ago
  1. #include <stdio.h>
  2. const int N = 16;
  3. const int blocksize = 16;
  4. #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
  5. inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
  6. {
  7. if (code != cudaSuccess)
  8. {
  9. fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
  10. if (abort) exit(code);
  11. }
  12. }
  13. __global__
  14. void hello(char *a, int *b)
  15. {
  16. a[threadIdx.x] += b[threadIdx.x];
  17. }
  18. namespace stormcuda {
  19. namespace graph {
  20. void helloWorld() {
  21. printf("CUDA TEST START\n");
  22. printf("Should print \"Hello World\"\n");
  23. char a[N] = "Hello \0\0\0\0\0\0";
  24. int b[N] = {15, 10, 6, 0, -11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  25. char c[N] = "YELLO \0\0\0\0\0\0";
  26. char *ad;
  27. int *bd;
  28. const int csize = N * sizeof(char);
  29. const int isize = N * sizeof(int);
  30. printf("%s", a);
  31. cudaMalloc((void **) &ad, csize);
  32. cudaMalloc((void **) &bd, isize);
  33. cudaMemcpy(ad, a, csize, cudaMemcpyHostToDevice);
  34. cudaMemcpy(bd, b, isize, cudaMemcpyHostToDevice);
  35. dim3 dimBlock(blocksize, 1);
  36. dim3 dimGrid(1, 1);
  37. hello << < dimGrid, dimBlock >> > (ad, bd);
  38. gpuErrchk(cudaPeekAtLastError());
  39. gpuErrchk(cudaDeviceSynchronize());
  40. cudaMemcpy(c, ad, csize, cudaMemcpyDeviceToHost);
  41. cudaFree(ad);
  42. cudaFree(bd);
  43. printf("%s\n", c);
  44. printf("CUDA TEST END\n");
  45. }
  46. }
  47. }