Skip to content

Commit

Permalink
Merge branch 'ershi/pass-program-name-to-nvrtc' into 'main'
Browse files Browse the repository at this point in the history
Pass the program name to NVRTC

See merge request omniverse/warp!973
  • Loading branch information
shi-eric committed Jan 14, 2025
2 parents af3b467 + bc0b366 commit 1d8aba6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions warp/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ def build_cuda(
):
with open(cu_path, "rb") as src_file:
src = src_file.read()
cu_path = cu_path.encode("utf-8")
cu_path_bytes = cu_path.encode("utf-8")
program_name_bytes = os.path.basename(cu_path).encode("utf-8")
inc_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "native").encode("utf-8")
output_path = output_path.encode("utf-8")

if warp.config.llvm_cuda:
warp.context.runtime.llvm.compile_cuda(src, cu_path, inc_path, output_path, False)
warp.context.runtime.llvm.compile_cuda(src, cu_path_bytes, inc_path, output_path, False)

else:
if ltoirs is None:
Expand All @@ -34,6 +35,7 @@ def build_cuda(
arr_lroir_sizes = (ctypes.c_size_t * num_ltoirs)(*[len(l) for l in ltoirs])
err = warp.context.runtime.core.cuda_compile_program(
src,
program_name_bytes,
arch,
inc_path,
0,
Expand Down
1 change: 1 addition & 0 deletions warp/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3473,6 +3473,7 @@ def __init__(self):

self.core.cuda_compile_program.argtypes = [
ctypes.c_char_p, # cuda_src
ctypes.c_char_p, # program name
ctypes.c_int, # arch
ctypes.c_char_p, # include_dir
ctypes.c_int, # num_cuda_include_dirs
Expand Down
2 changes: 1 addition & 1 deletion warp/native/warp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ WP_API bool cuda_graph_end_capture(void* context, void* stream, void** graph_ret
WP_API bool cuda_graph_launch(void* graph, void* stream) { return false; }
WP_API bool cuda_graph_destroy(void* context, void* graph) { return false; }

WP_API size_t cuda_compile_program(const char* cuda_src, int arch, const char* include_dir, int num_cuda_include_dirs, const char** cuda_include_dirs, bool debug, bool verbose, bool verify_fp, bool fast_math, bool fuse_fp, const char* output_path, size_t num_ltoirs, char** ltoirs, size_t* ltoir_sizes) { return 0; }
WP_API size_t cuda_compile_program(const char* cuda_src, const char* program_name, int arch, const char* include_dir, int num_cuda_include_dirs, const char** cuda_include_dirs, bool debug, bool verbose, bool verify_fp, bool fast_math, bool fuse_fp, const char* output_path, size_t num_ltoirs, char** ltoirs, size_t* ltoir_sizes) { return 0; }

WP_API void* cuda_load_module(void* context, const char* ptx) { return NULL; }
WP_API void cuda_unload_module(void* context, void* module) {}
Expand Down
4 changes: 2 additions & 2 deletions warp/native/warp.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2654,7 +2654,7 @@ bool write_file(const char* data, size_t size, std::string filename, const char*
}
#endif

size_t cuda_compile_program(const char* cuda_src, int arch, const char* include_dir, int num_cuda_include_dirs, const char** cuda_include_dirs, bool debug, bool verbose, bool verify_fp, bool fast_math, bool fuse_fp, const char* output_path, size_t num_ltoirs, char** ltoirs, size_t* ltoir_sizes)
size_t cuda_compile_program(const char* cuda_src, const char* program_name, int arch, const char* include_dir, int num_cuda_include_dirs, const char** cuda_include_dirs, bool debug, bool verbose, bool verify_fp, bool fast_math, bool fuse_fp, const char* output_path, size_t num_ltoirs, char** ltoirs, size_t* ltoir_sizes)
{
// use file extension to determine whether to output PTX or CUBIN
const char* output_ext = strrchr(output_path, '.');
Expand Down Expand Up @@ -2757,7 +2757,7 @@ size_t cuda_compile_program(const char* cuda_src, int arch, const char* include_
res = nvrtcCreateProgram(
&prog, // prog
cuda_src, // buffer
NULL, // name
program_name, // name
0, // numHeaders
NULL, // headers
NULL); // includeNames
Expand Down
2 changes: 1 addition & 1 deletion warp/native/warp.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ extern "C"
WP_API bool cuda_graph_launch(void* graph, void* stream);
WP_API bool cuda_graph_destroy(void* context, void* graph);

WP_API size_t cuda_compile_program(const char* cuda_src, int arch, const char* include_dir, int num_cuda_include_dirs, const char** cuda_include_dirs, bool debug, bool verbose, bool verify_fp, bool fast_math, bool fuse_fp, const char* output_path, size_t num_ltoirs, char** ltoirs, size_t* ltoir_sizes);
WP_API size_t cuda_compile_program(const char* cuda_src, const char* program_name, int arch, const char* include_dir, int num_cuda_include_dirs, const char** cuda_include_dirs, bool debug, bool verbose, bool verify_fp, bool fast_math, bool fuse_fp, const char* output_path, size_t num_ltoirs, char** ltoirs, size_t* ltoir_sizes);
WP_API bool cuda_compile_fft(const char* ltoir_output_path, const char* symbol_name, int num_include_dirs, const char** include_dirs, const char* mathdx_include_dir, int arch, int size, int elements_per_thread, int direction, int precision, int* shared_memory_size);
WP_API bool cuda_compile_dot(const char* ltoir_output_path, const char* symbol_name, int num_include_dirs, const char** include_dirs, const char* mathdx_include_dir, int arch, int M, int N, int K, int precision_A, int precision_B, int precision_C, int type, int arrangement_A, int arrangement_B, int arrangement_C, int num_threads);

Expand Down

0 comments on commit 1d8aba6

Please sign in to comment.