Skip to content

Commit

Permalink
Add example for cuda_binary and cuda_test macros
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhan committed Oct 27, 2023
1 parent 3dc08d2 commit f5df086
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/basic_macros/BUILD.bazel
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"],
)
26 changes: 26 additions & 0 deletions examples/basic_macros/main.cu
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;
}

0 comments on commit f5df086

Please sign in to comment.