-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[NVSHMEM] Extend CUDA backend to compile and link TIR modules with NVSHMEM #18093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,12 +106,26 @@ void InitNVSHMEMWrapper(String args) { | |
| InitNVSHMEM(uid_64, num_workers, worker_id_start); | ||
| } | ||
|
|
||
| void NVSHMEMXCumoduleInit(void* cuModule) { | ||
| CUmodule mod = static_cast<CUmodule>(cuModule); | ||
| auto status = nvshmemx_init_status(); | ||
| // The NVSHMEM library must have completed device initialization prior to | ||
| // nvshmemx_cumodule_init. If not, we skip the cumodule initialization. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if not device initialized, we should return with error
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The design here is to enable NVSHMEM compilation and linking broadly for every kernel, including those whose NVSHMEM context is not initialized and do not use NVSHMEM in their kernels. In such case, |
||
| if (status == NVSHMEM_STATUS_IS_INITIALIZED || status == NVSHMEM_STATUS_LIMITED_MPG || | ||
| status == NVSHMEM_STATUS_FULL_MPG) { | ||
| int result = nvshmemx_cumodule_init(mod); | ||
| ICHECK_EQ(result, 0) << "nvshmemx_cumodule_init failed with error code: " << result; | ||
| } | ||
| } | ||
|
|
||
| TVM_FFI_REGISTER_GLOBAL("runtime.disco.nvshmem.init_nvshmem_uid").set_body_typed(InitNVSHMEMUID); | ||
|
|
||
| TVM_FFI_REGISTER_GLOBAL("runtime.disco.nvshmem.init_nvshmem").set_body_typed(InitNVSHMEM); | ||
|
|
||
| TVM_FFI_REGISTER_GLOBAL("runtime.disco.nvshmem.init_nvshmem_wrapper") | ||
| .set_body_typed(InitNVSHMEMWrapper); | ||
|
|
||
| TVM_FFI_REGISTER_GLOBAL("runtime.nvshmem.cumodule_init").set_body_typed(NVSHMEMXCumoduleInit); | ||
|
|
||
| } // namespace runtime | ||
| } // namespace tvm | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -297,19 +297,10 @@ std::string CodeGenCUDA::Finish() { | |
| decl_stream << "#define TVM_ENABLE_L2_PREFETCH 0\n"; | ||
| decl_stream << "#endif\n"; | ||
|
|
||
| decl_stream << "\n#ifdef _WIN32\n"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because NVSHMEM contains |
||
| decl_stream << " using uint = unsigned int;\n"; | ||
| decl_stream << " using uchar = unsigned char;\n"; | ||
| decl_stream << " using ushort = unsigned short;\n"; | ||
| decl_stream << " using int64_t = long long;\n"; | ||
| decl_stream << " using uint64_t = unsigned long long;\n"; | ||
| decl_stream << "#else\n"; | ||
| decl_stream << " #define uint unsigned int\n"; | ||
| decl_stream << " #define uchar unsigned char\n"; | ||
| decl_stream << " #define ushort unsigned short\n"; | ||
| decl_stream << " #define int64_t long long\n"; | ||
| decl_stream << " #define uint64_t unsigned long long\n"; | ||
| decl_stream << "#endif\n"; | ||
| decl_stream << "#include <cstdint>\n"; | ||
| decl_stream << "using uint = unsigned int;\n"; | ||
| decl_stream << "using uchar = unsigned char;\n"; | ||
| decl_stream << "using ushort = unsigned short;\n"; | ||
|
|
||
| return CodeGenC::Finish(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change intentional?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the latest dlpack,
DLDeviceTypehas enum values 1 to 17. The valueDevice(device_type=0, device_id=0)would raise an error of unrecognized device type. Since it is meant to indicate a Null value, I replace the subsequent usage withOptional<Device>type, see the changes ofUseDefaultDeviceIfNone.