-
Notifications
You must be signed in to change notification settings - Fork 29
Add support for raw_kernel_arg extension #2038
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
base: master
Are you sure you want to change the base?
Conversation
libsyclinterface/include/syclinterface/dpctl_sycl_extension_interface.h
Outdated
Show resolved
Hide resolved
DPCTL_API | ||
void DPCTLRawKernelArg_Delete(__dpctl_take DPCTLSyclRawKernelArgRef Ref) | ||
{ | ||
delete unwrap<RawKernelArgData>(Ref); |
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.
auto RawArg = unwrap<RawKernelArgData>(Ref);
delete[] RawArg->bytes;
delete RawArg;
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 changed the approach slightly to hold the data in a std::vector
inside RawKernelArgDataTy
, because delete[] RawArg->bytes
gave a warning about incomplete delete.
std::memcpy(rawData.get(), bytes, count); | ||
auto RawKernelArg = std::unique_ptr<RawKernelArgData>( | ||
new RawKernelArgData{rawData.release(), count}); | ||
rka = wrap<RawKernelArgData>(RawKernelArg.release()); |
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.
Sorry. I've misled you in my previous comment about unique_ptr
. To make it work it should be something like this:
auto rawData =
std::unique_ptr<unsigned char[]>(new unsigned char[count]);
std::memcpy(rawData.get(), bytes, count);
auto RawKernelArg = std::unique_ptr<RawKernelArgData>(
new RawKernelArgData{rawData.get(), count});
rka = wrap<RawKernelArgData>(RawKernelArg.get());
RawKernelArg.release();
rawData.release();
Otherwise rawData
would leak if new RawKernelArgData{rawData.release(), count}
throws.
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 changed the approach slightly to hold the data in a std::vector
inside RawKernelArgDataTy
.
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.
@sommerlukas this is a good idea, but I'm not sure about this. As far as I understand this part of API should be C-api, so we can't use c++ classes and/or constructors/destructors.
But I'm not sure about it.
Let's ask @ndgrigorian
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.
My understanding was that only the interface of libsyclinterface
needs to be C-like. We use std::vector
in other parts of libsyclinterface
, e.g., here.
But happy to wait for confirmation from @ndgrigorian.
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.
std::vector
is used indeed. The same as std::unique_ptr
. But it is in .cpp
file. Not in header file which actually has .h
extension and not .hpp
and extern "C"
declaration (https://github.com/IntelPython/dpctl/pull/2038/files#diff-bc26687692ae358c908d9587e3abdfab35454bc0fcab36f47cf59af185e6b5fdR40)
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.
@AlexanderKalistratov is correct, and this is the reason why the dpctl-typed opaque pointers for std::vector
s exist (i.e., DPCTLDeviceVector
, etc.)
We could add another of such types for this implementation though.
@sommerlukas |
1ea6b9c
to
296e236
Compare
#include <cstring> | ||
#include <vector> |
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.
These seem to be causing the test failures
typedef class RawKernelArgDataTy | ||
{ | ||
public: | ||
RawKernelArgDataTy(void *bytes, size_t count) : data(count) | ||
{ | ||
std::memcpy(data.data(), bytes, count); | ||
} |
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.
Unfortunately, the use of copying and cstring
also brought about another problem, namely, that this is now a class with a constructor under extern "C"
linkage.
Builds fail but also, it won't be constructible from C with this constructor due to name-mangling issues.
Switch approach to not introduce an intermediate struct, but have the opaque pointer directly point to std::vector instead.
Thanks for the feedback @ndgrigorian @AlexanderKalistratov! After taking a look at how the opaque pointers for other |
ba642e9
to
a0b4c75
Compare
Add support for the DPC++ SYCL extension
raw_kernel_arg
that allows to pass a binary blob as kernel arguments.This is for example useful if the kernel uses a
struct
as kernel parameter, but is loaded from SPIR-V and the argument type is unknown forset_arg
.The implementation follows #1984.