-
Notifications
You must be signed in to change notification settings - Fork 43
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
Support for cl_mem_device_address_EXT #742
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks for this contribution! I have had a first look at this change. I have also made a few comments on the proposed extension specification, which I don't think we can really consider it settled/stable yet. Happy to keep iterating on both.
|
||
|
||
#endif // cl_ext_buffer_device_address | ||
|
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.
I have discussed releasing this extension with the Khronos OpenCL working group. The authors seem motivated to make it happen. In the meantime, I suggest you move all definitions that will be provided by the headers to src/cl_headers.hpp
.
@@ -303,6 +328,7 @@ static const std::unordered_map<std::string, void*> gExtensionEntrypoints = { | |||
EXTENSION_ENTRYPOINT(clCreateCommandQueueWithPropertiesKHR), | |||
EXTENSION_ENTRYPOINT(clGetKernelSuggestedLocalWorkSizeKHR), | |||
{"clGetKernelSubGroupInfoKHR", FUNC_PTR(clGetKernelSubGroupInfo)}, | |||
{"clSetKernelArgDevicePointerEXT", FUNC_PTR(clSetKernelArgDevicePointerEXT_fn)}, |
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.
{"clSetKernelArgDevicePointerEXT", FUNC_PTR(clSetKernelArgDevicePointerEXT_fn)}, | |
{"clSetKernelArgDevicePointerEXT", FUNC_PTR(clSetKernelArgDevicePointerEXT)}, |
For consistency with other extensions. You could then just use EXTENSION_ENTRYPOINT
I think.
ret = CL_INVALID_OPERATION; | ||
break; | ||
} | ||
val_sizet = buffer->device_address(); |
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.
The spec defines a new type that aliases cl_ulong
which, contrary to size_t
is guaranteed to have a size of 64 bits.
#endif | ||
|
||
typedef cl_ulong cl_mem_device_address_EXT; | ||
|
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.
Please move these definitions to cl_headers.hpp
for now.
@@ -47,6 +47,9 @@ struct cvk_platform; | |||
|
|||
struct cvk_device : public _cl_device_id, | |||
object_magic_header<object_magic::device> { | |||
/// Map for storing device pointers to buffer pointers | |||
/// Support cl_ext_buffer_device_address | |||
std::unordered_map<void*, void*> device_to_buffer_map; |
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.
Those pointers would only be valid for a given context. I think we probably want to keep this state in cvk_context
. Please use the specific types instead of void*
.
@@ -626,6 +626,7 @@ void cvk_device::build_extension_ils_list() { | |||
// Add always supported extensions | |||
MAKE_NAME_VERSION(1, 0, 0, "cl_khr_extended_versioning"), | |||
MAKE_NAME_VERSION(1, 0, 0, "cl_khr_create_command_queue"), | |||
MAKE_NAME_VERSION(1, 0, 0, "cl_ext_buffer_device_address"), |
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.
The current spec drafts does not define 1.0.0, only 0.1.0, 0.2.0, and 0.3.0.
|
||
std::cout << "All tests completed successfully\n"; | ||
return 0; | ||
} |
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.
I'm guessing the intention is to move all the test code to tests/api/buffer_device_address.cpp
, isn't it?
// device pointer found in map, swapping the buffer pointer | ||
auto buffer_ptr_raw = it->second; | ||
auto buffer_ptr = reinterpret_cast<cvk_buffer*>(buffer_ptr_raw); | ||
m_kernel_resources[arg.binding] = buffer_ptr; |
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.
This will break the existing argument setting for buffers. It might be easier/cleaner to introduce a new cvk_kernel::set_arg_device_address
function (that would have to also mark the argument as set as done by line 361).
// First check if device supports the extension | ||
size_t ext_size; | ||
GetDeviceInfo(CL_DEVICE_EXTENSIONS, 0, nullptr, &ext_size); | ||
|
||
std::vector<char> extensions(ext_size); | ||
GetDeviceInfo(CL_DEVICE_EXTENSIONS, ext_size, extensions.data(), nullptr); | ||
|
||
bool hasBufferDeviceAddress = | ||
std::string(extensions.data()).find("cl_ext_buffer_device_address") != std::string::npos; | ||
|
||
if (!hasBufferDeviceAddress) { | ||
GTEST_SKIP() << "Device does not support cl_ext_buffer_device_address extension"; | ||
} |
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.
// First check if device supports the extension | |
size_t ext_size; | |
GetDeviceInfo(CL_DEVICE_EXTENSIONS, 0, nullptr, &ext_size); | |
std::vector<char> extensions(ext_size); | |
GetDeviceInfo(CL_DEVICE_EXTENSIONS, ext_size, extensions.data(), nullptr); | |
bool hasBufferDeviceAddress = | |
std::string(extensions.data()).find("cl_ext_buffer_device_address") != std::string::npos; | |
if (!hasBufferDeviceAddress) { | |
GTEST_SKIP() << "Device does not support cl_ext_buffer_device_address extension"; | |
} | |
// First check if device supports the extension | |
REQUIRE_EXTENSION("cl_ext_buffer_device_address"); |
This is being introduced by #748 for another test.
@kpet thank you for the review, I'll work on addressing your comments. Meanwhile, this is what I get when I try to execute an example:
I'm not an LLVM expert but just wanted to check with you first before I investigate further. |
Can you share the kernel source and the command line? Everything will be in clvk's log, that you would get running with:
then upload |
The kernel source is a HIP matrix multiplication @rjodinchr |
The error message you have posted is about |
Oh, I understand what you meant by:
This application is using OpenCL SPIR-V source. This was not clear to me as SPIR-V has 2 variant. The OpenCL one and the Vulkan one. While the goal of clvk is to compile whatever CL source it gets to Vulkan SPIR-V, it can take OpenCL SPIR-V as the input. But the log does not contain the OpenCL SPIR-V inputs. Could you share the sources then (I see two calls to |
Hmm only one got dumped for me:
|
I'll try to reproduce with that one then. Thank you |
I'm not able to reproduce.
That should produce a |
|
So the issue is that We can force
This is because we have the following line in the OpenCL SPIR-V kernel:
Which gets translated into the following LLVM IR (by
Note that it is on Removing every trace of
|
|
Disabled it, and I was able to run a HIP example on Vulkan!
|
|
still WIP, sample works but test fails though more tests fail even on main