-
Notifications
You must be signed in to change notification settings - Fork 769
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
How to create program objects from SPIRV with clCreateProgramWithBinary runtime API . #3124
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
Comments
For OpenCL it is: clCreateProgramWithIL (https://www.khronos.org/registry/OpenCL/sdk/2.1/docs/man/xhtml/clCreateProgramWithIL.html). I think this is an OK example. |
thx your reply @MrSidims , I will try it. |
@malixian, could you clarify how are you going to use the program object? |
I want to build a program object by myopencl with spir that is generated by dpcpp. And codes the main program to emti kernel in spir style to myopencl. I think the examples from the link shows me how to program. |
I'd like to note that ABI for SPIR kernels generated by DPC++ compiler is implementation defined. Some implementation details are documented here: https://github.com/intel/llvm/blob/sycl/sycl/doc/CompilerAndRuntimeDesign.md, but it's subject to change. I would not recommend using this approach "in production". |
Whether the SPIR generated by dpcpp can be used to program with amd-opencl |
No.
It depends on the DPC++ features used by the application, but in most cases the answer is yes. |
thx very much @bader . |
BTW, if my amd-opencl supports SPIR-V and the SPIR-V generated by DPC++ don't have extensioncan, it's work? |
This setup should work. |
Can you give me some code that can be compiled into spirv without extensions? thank you very much. |
For example: #include <CL/sycl.hpp>
int main() {
// Creating buffer of 4 ints to be used inside the kernel code
cl::sycl::buffer<cl::sycl::cl_int, 1> Buffer(4);
// Creating SYCL queue
cl::sycl::queue Queue;
// Size of index space for kernel
cl::sycl::range<1> NumOfWorkItems{Buffer.get_count()};
// Submitting command group(work) to queue
Queue.submit([&](cl::sycl::handler &cgh) {
// Getting write only access to the buffer on a device
auto Accessor = Buffer.get_access<cl::sycl::access::mode::write>(cgh);
// Executing kernel
cgh.parallel_for<class FillBuffer>(
NumOfWorkItems, [=](cl::sycl::id<1> WIid) {
// Fill buffer with indexes
Accessor[WIid] = (cl::sycl::cl_int)WIid.get(0);
});
});
// Getting read only access to the buffer on the host.
// Implicit barrier waiting for queue to complete the work.
const auto HostAccessor = Buffer.get_access<cl::sycl::access::mode::read>();
// Check the results
bool MismatchFound = false;
for (size_t I = 0; I < Buffer.get_count(); ++I) {
if (HostAccessor[I] != I) {
std::cout << "The result is incorrect for element: " << I
<< " , expected: " << I << " , got: " << HostAccessor[I]
<< std::endl;
MismatchFound = true;
}
}
if (!MismatchFound) {
std::cout << "The results are correct!" << std::endl;
}
return MismatchFound;
} |
Thank you so much for your generous help @bader ! |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I can emit SPIRV with command
clang++ -fsycl -fsycl-device-only -fno-sycl-use-bitcode test.cpp
.And I would like to know how to create program objects from SPIRV with
clCreateProgramWithBinary
runtime API .If this way works, can you give me some examples?
The text was updated successfully, but these errors were encountered: