-
Notifications
You must be signed in to change notification settings - Fork 9
[Perf] Streams 2: Add AMDGPU/HIP stream support #408
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
Draft
hughperkins
wants to merge
8
commits into
hp/streams-quadrantsic-1-cuda-streams
Choose a base branch
from
hp/streams-quadrantsic-2-amdgpu-cpu
base: hp/streams-quadrantsic-1-cuda-streams
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7bd18ca
Add AMDGPU/HIP stream support and async memory operations
hughperkins b133bd7
Merge branch 'hp/streams-quadrantsic-1-cuda-streams' into hp/streams-…
hughperkins 7555ec5
Move AMDGPU mem_free_async before transfers sync to match CUDA ordering
hughperkins c12d23e
Convert AMDGPU sync memcpy_host_to_device to async on active_stream
hughperkins 1673a38
Document ROCm >= 5.4 requirement for hipMallocAsync/hipFreeAsync
hughperkins 60d015b
Relax concurrency test threshold and log timings
hughperkins c4be4ff
Add handle==0 guard to AMDGPU stream_synchronize and make stream_ thr…
hughperkins b28e7c6
Revert "Relax concurrency test threshold and log timings"
hughperkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #include "quadrants/runtime/amdgpu/kernel_launcher.h" | ||
| #include "quadrants/rhi/amdgpu/amdgpu_context.h" | ||
| #include "quadrants/rhi/amdgpu/amdgpu_driver.h" | ||
| #include "quadrants/program/launch_context_builder.h" | ||
|
|
||
| namespace quadrants::lang { | ||
|
|
@@ -32,18 +33,14 @@ void KernelLauncher::launch_llvm_kernel(Handle handle, | |
| transfers; | ||
| std::unordered_map<ArgArrayPtrKey, void *, ArgArrayPtrKeyHasher> device_ptrs; | ||
|
|
||
| auto *active_stream = AMDGPUContext::get_instance().get_stream(); | ||
|
|
||
| char *device_result_buffer{nullptr}; | ||
| // Here we have to guarantee the result_result_buffer isn't nullptr | ||
| // It is interesting - The code following | ||
| // L60: DeviceAllocation devalloc = | ||
| // executor->allocate_memory_on_device( call another kernel and it will result | ||
| // in | ||
| // Memory access fault by GPU node-1 (Agent handle: 0xeda5ca0) on address | ||
| // (nil). Reason: Page not present or supervisor privilege. | ||
| // if you don't allocate it. | ||
|
Comment on lines
-36
to
-43
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 did you remove this comment? It is no longer applicable? It is irrelevant? |
||
| AMDGPUDriver::get_instance().malloc( | ||
| // Must always allocate device_result_buffer (even when result_buffer_size | ||
| // is 0) to avoid memory access faults from allocate_memory_on_device below. | ||
| AMDGPUDriver::get_instance().malloc_async( | ||
| (void **)&device_result_buffer, | ||
| std::max(ctx.result_buffer_size, sizeof(uint64))); | ||
| std::max(ctx.result_buffer_size, sizeof(uint64)), active_stream); | ||
|
|
||
| for (int i = 0; i < (int)parameters.size(); i++) { | ||
| const auto &kv = parameters[i]; | ||
|
|
@@ -69,8 +66,9 @@ void KernelLauncher::launch_llvm_kernel(Handle handle, | |
| executor->get_device_alloc_info_ptr(devalloc); | ||
| transfers[data_ptr_idx] = {data_ptr, devalloc}; | ||
|
|
||
| AMDGPUDriver::get_instance().memcpy_host_to_device( | ||
| (void *)device_ptrs[data_ptr_idx], data_ptr, arr_sz); | ||
| AMDGPUDriver::get_instance().memcpy_host_to_device_async( | ||
| (void *)device_ptrs[data_ptr_idx], data_ptr, arr_sz, | ||
| active_stream); | ||
| } | ||
| ctx.set_ndarray_ptrs(arg_id, (uint64)device_ptrs[data_ptr_idx], | ||
| (uint64)ctx.array_ptrs[grad_ptr_idx]); | ||
|
|
@@ -86,27 +84,28 @@ void KernelLauncher::launch_llvm_kernel(Handle handle, | |
| } | ||
| } | ||
| if (transfers.size() > 0) { | ||
| AMDGPUDriver::get_instance().stream_synchronize(nullptr); | ||
| AMDGPUDriver::get_instance().stream_synchronize(active_stream); | ||
| } | ||
| char *host_result_buffer = (char *)ctx.get_context().result_buffer; | ||
| if (ctx.result_buffer_size > 0) { | ||
| // Malloc_Async and Free_Async are available after ROCm 5.4 | ||
| ctx.get_context().result_buffer = (uint64 *)device_result_buffer; | ||
| } | ||
| char *device_arg_buffer = nullptr; | ||
| if (ctx.arg_buffer_size > 0) { | ||
| AMDGPUDriver::get_instance().malloc((void **)&device_arg_buffer, | ||
| ctx.arg_buffer_size); | ||
| AMDGPUDriver::get_instance().memcpy_host_to_device( | ||
| device_arg_buffer, ctx.get_context().arg_buffer, ctx.arg_buffer_size); | ||
| AMDGPUDriver::get_instance().malloc_async( | ||
| (void **)&device_arg_buffer, ctx.arg_buffer_size, active_stream); | ||
| AMDGPUDriver::get_instance().memcpy_host_to_device_async( | ||
| device_arg_buffer, ctx.get_context().arg_buffer, ctx.arg_buffer_size, | ||
| active_stream); | ||
| ctx.get_context().arg_buffer = device_arg_buffer; | ||
| } | ||
| void *context_pointer; | ||
| int arg_size = sizeof(RuntimeContext *); | ||
| AMDGPUDriver::get_instance().malloc((void **)&context_pointer, | ||
| sizeof(RuntimeContext)); | ||
| AMDGPUDriver::get_instance().memcpy_host_to_device( | ||
| context_pointer, &ctx.get_context(), sizeof(RuntimeContext)); | ||
| AMDGPUDriver::get_instance().malloc_async( | ||
| (void **)&context_pointer, sizeof(RuntimeContext), active_stream); | ||
| AMDGPUDriver::get_instance().memcpy_host_to_device_async( | ||
| context_pointer, &ctx.get_context(), sizeof(RuntimeContext), | ||
| active_stream); | ||
|
|
||
| AMDGPUContext::get_instance().push_back_kernel_arg_pointer(context_pointer); | ||
|
|
||
|
|
@@ -119,13 +118,18 @@ void KernelLauncher::launch_llvm_kernel(Handle handle, | |
| } | ||
| QD_TRACE("Launching kernel"); | ||
| if (ctx.arg_buffer_size > 0) { | ||
| AMDGPUDriver::get_instance().mem_free(device_arg_buffer); | ||
| AMDGPUDriver::get_instance().mem_free_async(device_arg_buffer, | ||
| active_stream); | ||
| } | ||
| if (ctx.result_buffer_size > 0) { | ||
| AMDGPUDriver::get_instance().memcpy_device_to_host( | ||
| host_result_buffer, device_result_buffer, ctx.result_buffer_size); | ||
| AMDGPUDriver::get_instance().memcpy_device_to_host_async( | ||
| host_result_buffer, device_result_buffer, ctx.result_buffer_size, | ||
| active_stream); | ||
| } | ||
| AMDGPUDriver::get_instance().mem_free_async(device_result_buffer, | ||
| active_stream); | ||
| if (transfers.size()) { | ||
| AMDGPUDriver::get_instance().stream_synchronize(active_stream); | ||
| for (auto itr = transfers.begin(); itr != transfers.end(); itr++) { | ||
| auto &idx = itr->first; | ||
| auto arg_id = idx.arg_id; | ||
|
|
@@ -135,8 +139,6 @@ void KernelLauncher::launch_llvm_kernel(Handle handle, | |
| executor->deallocate_memory_on_device(itr->second.second); | ||
| } | ||
| } | ||
| // Since we always allocating above then we should always free | ||
| AMDGPUDriver::get_instance().mem_free(device_result_buffer); | ||
| } | ||
|
|
||
| KernelLauncher::Handle KernelLauncher::register_llvm_kernel( | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe it is time to increase linewidth of C++ code. 80 chars is painful nowadays. I would recommend either 100 or 120, as a matter of taste.