-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL][HIP][CUDA] Use new version of piMemGetNativeHandle and add test #12297
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6fa2c98
Use new version of piMemGetNativeHandle and add test
e06ca16
Bump PI version major
300de38
Update PiMockPlugin.hpp so that MemGetNativeHandle has a device param
c35df73
Update sycl/plugins/unified_runtime/CMakeLists.txt
hdelan 2a05505
Apply suggestions from code review
hdelan 32f957c
Update test
14e351e
Update test
7725cc9
Update sycl/test-e2e/HostInteropTask/interop-task-hip.cpp
hdelan 3245288
Add comments explaining why nullptr is passed for dev arg
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
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 |
---|---|---|
|
@@ -56,14 +56,14 @@ endif() | |
if(SYCL_PI_UR_USE_FETCH_CONTENT) | ||
include(FetchContent) | ||
|
||
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime") | ||
# commit 3225b822b5d8cbfa85d7fc1bd5a5bf96e5bb8c1a | ||
# Merge: edb281f3 5fc41099 | ||
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git") | ||
# commit d216eb44d5c9fe3433eecdd09b10e3e79ac25bd7 | ||
# Merge: 40517d2b fc1f3066 | ||
# Author: Kenneth Benzie (Benie) <[email protected]> | ||
# Date: Tue Jan 30 12:31:44 2024 +0000 | ||
# Merge pull request #1168 from Seanst98/sean/unique-addr-mode-per-dim-adapters | ||
# [Bindless][CUDA] Unique addressing modes per dimension | ||
set(UNIFIED_RUNTIME_TAG 3225b822b5d8cbfa85d7fc1bd5a5bf96e5bb8c1a) | ||
# Date: Wed Jan 31 10:38:07 2024 +0000 | ||
# Merge pull request #1226 from hdelan/get-native-mem-on-device2 | ||
# [UR] Add extra param to urMemGetNativeHandle | ||
set(UNIFIED_RUNTIME_TAG d216eb44d5c9fe3433eecdd09b10e3e79ac25bd7) | ||
|
||
if(SYCL_PI_UR_OVERRIDE_FETCH_CONTENT_REPO) | ||
set(UNIFIED_RUNTIME_REPO "${SYCL_PI_UR_OVERRIDE_FETCH_CONTENT_REPO}") | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// FIXME: the rocm include path and link path are highly platform dependent, | ||
// we should set this with some variable instead. | ||
// RUN: %{build} -o %t.out -I/opt/rocm/include -L/opt/rocm/lib -lamdhip64 | ||
// RUN: %{run} %t.out | ||
// REQUIRES: hip | ||
|
||
#include <iostream> | ||
#include <sycl/sycl.hpp> | ||
|
||
#define __HIP_PLATFORM_AMD__ | ||
hdelan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#include <hip/hip_runtime.h> | ||
|
||
using namespace sycl; | ||
using namespace sycl::access; | ||
|
||
static constexpr size_t BUFFER_SIZE = 1024; | ||
|
||
template <typename T> class Modifier; | ||
|
||
template <typename T> class Init; | ||
|
||
template <typename BufferT, typename ValueT> | ||
void checkBufferValues(BufferT Buffer, ValueT Value) { | ||
auto Acc = Buffer.get_host_access(); | ||
for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) { | ||
if (Acc[Idx] != Value) { | ||
std::cerr << "buffer[" << Idx << "] = " << Acc[Idx] | ||
<< ", expected val = " << Value << '\n'; | ||
exit(1); | ||
} | ||
} | ||
} | ||
|
||
template <typename DataT> | ||
void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) { | ||
Q.submit([&](handler &CGH) { | ||
auto SrcA = Src.template get_access<mode::read>(CGH); | ||
auto DstA = Dst.template get_access<mode::write>(CGH); | ||
|
||
auto Func = [=](interop_handle IH) { | ||
auto HipStream = IH.get_native_queue<backend::ext_oneapi_hip>(); | ||
auto SrcMem = IH.get_native_mem<backend::ext_oneapi_hip>(SrcA); | ||
auto DstMem = IH.get_native_mem<backend::ext_oneapi_hip>(DstA); | ||
|
||
if (hipMemcpyWithStream(DstMem, SrcMem, sizeof(DataT) * SrcA.get_count(), | ||
hipMemcpyDefault, HipStream) != hipSuccess) { | ||
throw; | ||
} | ||
|
||
if (hipStreamSynchronize(HipStream) != hipSuccess) { | ||
throw; | ||
} | ||
|
||
if (Q.get_backend() != IH.get_backend()) | ||
throw; | ||
}; | ||
CGH.host_task(Func); | ||
}); | ||
} | ||
|
||
template <typename DataT> void modify(buffer<DataT, 1> &B, queue &Q) { | ||
Q.submit([&](handler &CGH) { | ||
auto Acc = B.template get_access<mode::read_write>(CGH); | ||
|
||
auto Kernel = [=](item<1> Id) { Acc[Id] += 1; }; | ||
|
||
CGH.parallel_for<Modifier<DataT>>(Acc.get_count(), Kernel); | ||
}); | ||
} | ||
|
||
template <typename DataT, DataT B1Init, DataT B2Init> | ||
void init(buffer<DataT, 1> &B1, buffer<DataT, 1> &B2, queue &Q) { | ||
Q.submit([&](handler &CGH) { | ||
auto Acc1 = B1.template get_access<mode::write>(CGH); | ||
auto Acc2 = B2.template get_access<mode::write>(CGH); | ||
|
||
CGH.parallel_for<Init<DataT>>(BUFFER_SIZE, [=](item<1> Id) { | ||
Acc1[Id] = B1Init; | ||
Acc2[Id] = B2Init; | ||
}); | ||
}); | ||
} | ||
|
||
// Check that a single host-interop-task with a buffer will work. | ||
void test_ht_buffer(queue &Q) { | ||
buffer<int, 1> Buffer{BUFFER_SIZE}; | ||
|
||
Q.submit([&](handler &CGH) { | ||
auto Acc = Buffer.get_access<mode::write>(CGH); | ||
auto Func = [=](interop_handle IH) { /*A no-op */ }; | ||
CGH.host_task(Func); | ||
}); | ||
} | ||
|
||
// A test that uses HIP interop to copy data from buffer A to buffer B, by | ||
// getting HIP ptrs and calling the hipMemcpyWithStream. Then run a SYCL | ||
// kernel that modifies the data in place for B, e.g. increment one, then copy | ||
// back to buffer A. Run it on a loop, to ensure the dependencies and the | ||
// reference counting of the objects is not leaked. | ||
void test_ht_kernel_dependencies(queue &Q) { | ||
static constexpr int COUNT = 4; | ||
buffer<int, 1> Buffer1{BUFFER_SIZE}; | ||
buffer<int, 1> Buffer2{BUFFER_SIZE}; | ||
|
||
// Init the buffer with a'priori invalid data. | ||
init<int, -1, -2>(Buffer1, Buffer2, Q); | ||
|
||
// Repeat a couple of times. | ||
for (size_t Idx = 0; Idx < COUNT; ++Idx) { | ||
copy(Buffer1, Buffer2, Q); | ||
modify(Buffer2, Q); | ||
copy(Buffer2, Buffer1, Q); | ||
} | ||
|
||
checkBufferValues(Buffer1, COUNT - 1); | ||
checkBufferValues(Buffer2, COUNT - 1); | ||
} | ||
|
||
void tests(queue &Q) { | ||
test_ht_buffer(Q); | ||
test_ht_kernel_dependencies(Q); | ||
} | ||
|
||
int main() { | ||
queue Q([](sycl::exception_list ExceptionList) { | ||
if (ExceptionList.size() != 1) { | ||
std::cerr << "Should be one exception in exception list" << std::endl; | ||
std::abort(); | ||
} | ||
std::rethrow_exception(*ExceptionList.begin()); | ||
}); | ||
tests(Q); | ||
std::cout << "Test PASSED" << std::endl; | ||
hdelan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 0; | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.