-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for cuda_binary and cuda_test macros
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load("@rules_cuda//cuda:defs.bzl", "cuda_binary", "cuda_test") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cuda_binary( | ||
name = "main", | ||
srcs = ["main.cu"], | ||
) | ||
|
||
cuda_test( | ||
name = "test", | ||
srcs = ["main.cu"], | ||
) |
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,26 @@ | ||
#include <cstdio> | ||
|
||
#define CUDA_CHECK(expr) \ | ||
do { \ | ||
cudaError_t err = (expr); \ | ||
if (err != cudaSuccess) { \ | ||
fprintf(stderr, "CUDA Error Code : %d\n Error String: %s\n", \ | ||
err, cudaGetErrorString(err)); \ | ||
exit(err); \ | ||
} \ | ||
} while (0) | ||
|
||
__global__ void kernel() { | ||
printf("cuda kernel called!\n"); | ||
} | ||
|
||
void launch() { | ||
kernel<<<1, 1>>>(); | ||
CUDA_CHECK(cudaGetLastError()); | ||
CUDA_CHECK(cudaDeviceSynchronize()); | ||
} | ||
|
||
int main() { | ||
launch(); | ||
return 0; | ||
} |