Skip to content

[SYCL] Replaces some of the CL_* enums with PI_* enums. #1239

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 4 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
340 changes: 218 additions & 122 deletions sycl/include/CL/sycl/detail/pi.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class queue {
/// \param Length is a number of bytes in the allocation.
/// \param Advice is a device-defined advice for the specified allocation.
/// \return an event representing advice operation.
event mem_advise(const void *Ptr, size_t Length, int Advice);
event mem_advise(const void *Ptr, size_t Length, pi_mem_advice Advice);

/// Provides hints to the runtime library that data should be made available
/// on a device earlier than Unified Shared Memory would normally require it
Expand Down
9 changes: 5 additions & 4 deletions sycl/source/detail/error_handling/enqueue_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ bool oclHandleInvalidWorkGroupSize(const device_impl &DeviceImpl,

size_t CompileWGSize[3] = {0};
Plugin.call<PiApiKind::piKernelGetGroupInfo>(
Kernel, Device, PI_KERNEL_COMPILE_GROUP_INFO_SIZE, sizeof(size_t) * 3,
CompileWGSize, nullptr);
Kernel, Device, PI_KERNEL_GROUP_INFO_COMPILE_WORK_GROUP_SIZE,
sizeof(size_t) * 3, CompileWGSize, nullptr);

if (CompileWGSize[0] != 0) {
// OpenCL 1.x && 2.0:
Expand Down Expand Up @@ -90,10 +90,11 @@ bool oclHandleInvalidWorkGroupSize(const device_impl &DeviceImpl,
// PI_INVALID_WORK_GROUP_SIZE if local_work_size is specified and the
// total number of work-items in the work-group computed as
// local_work_size[0] * ... * local_work_size[work_dim – 1] is greater
// than the value specified by PI_KERNEL_GROUP_INFO_SIZE in table 5.21.
// than the value specified by PI_KERNEL_GROUP_INFO_WORK_GROUP_SIZE in
// table 5.21.
size_t KernelWGSize = 0;
Plugin.call<PiApiKind::piKernelGetGroupInfo>(
Kernel, Device, PI_KERNEL_GROUP_INFO_SIZE, sizeof(size_t),
Kernel, Device, PI_KERNEL_GROUP_INFO_WORK_GROUP_SIZE, sizeof(size_t),
&KernelWGSize, nullptr);
const size_t TotalNumberOfWIs =
NDRDesc.LocalSize[0] * NDRDesc.LocalSize[1] * NDRDesc.LocalSize[2];
Expand Down
9 changes: 4 additions & 5 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ RT::PiEvent &event_impl::getHandleRef() { return MEvent; }

const ContextImplPtr &event_impl::getContextImpl() { return MContext; }

const plugin &event_impl::getPlugin() const {
return MContext->getPlugin();
}
const plugin &event_impl::getPlugin() const { return MContext->getPlugin(); }

void event_impl::setContextImpl(const ContextImplPtr &Context) {
MHostEvent = Context->is_host();
Expand All @@ -84,8 +82,9 @@ event_impl::event_impl(RT::PiEvent Event, const context &SyclContext)
}

RT::PiContext TempContext;
getPlugin().call<PiApiKind::piEventGetInfo>(
MEvent, CL_EVENT_CONTEXT, sizeof(RT::PiContext), &TempContext, nullptr);
getPlugin().call<PiApiKind::piEventGetInfo>(MEvent, PI_EVENT_INFO_CONTEXT,
sizeof(RT::PiContext),
&TempContext, nullptr);
if (MContext->getHandleRef() != TempContext) {
throw cl::sycl::invalid_parameter_error(
"The syclContext must match the OpenCL context associated with the "
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/event_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ template <info::event Param> struct get_event_info {
static RetType get(RT::PiEvent Event, const plugin &Plugin) {
RetType Result = (RetType)0;
// TODO catch an exception and put it to list of asynchronous exceptions
Plugin.call<PiApiKind::piEventGetInfo>(Event, cl_profiling_info(Param),
Plugin.call<PiApiKind::piEventGetInfo>(Event, pi_event_info(Param),
sizeof(Result), &Result, nullptr);
return Result;
}
Expand Down
28 changes: 15 additions & 13 deletions sycl/source/detail/program_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ program_impl::program_impl(ContextImplPtr Context, RT::PiProgram Program)
: MProgram(Program), MContext(Context), MLinkable(true) {

// TODO handle the case when cl_program build is in progress
cl_uint NumDevices;
pi_uint32 NumDevices;
const detail::plugin &Plugin = getPlugin();
Plugin.call<PiApiKind::piProgramGetInfo>(
Program, PI_PROGRAM_INFO_NUM_DEVICES, sizeof(cl_uint), &NumDevices, nullptr);
Plugin.call<PiApiKind::piProgramGetInfo>(Program, PI_PROGRAM_INFO_NUM_DEVICES,
sizeof(pi_uint32), &NumDevices,
nullptr);
vector_class<RT::PiDevice> PiDevices(NumDevices);
Plugin.call<PiApiKind::piProgramGetInfo>(Program, PI_PROGRAM_INFO_DEVICES,
sizeof(RT::PiDevice) * NumDevices,
Expand Down Expand Up @@ -267,8 +268,8 @@ vector_class<vector_class<char>> program_impl::get_binaries() const {
if (!is_host()) {
vector_class<size_t> BinarySizes(MDevices.size());
Plugin.call<PiApiKind::piProgramGetInfo>(
MProgram, PI_PROGRAM_INFO_BINARY_SIZES, sizeof(size_t) * BinarySizes.size(),
BinarySizes.data(), nullptr);
MProgram, PI_PROGRAM_INFO_BINARY_SIZES,
sizeof(size_t) * BinarySizes.size(), BinarySizes.data(), nullptr);

vector_class<char *> Pointers;
for (size_t I = 0; I < BinarySizes.size(); ++I) {
Expand Down Expand Up @@ -337,12 +338,12 @@ vector_class<RT::PiDevice> program_impl::get_pi_devices() const {
bool program_impl::has_cl_kernel(const string_class &KernelName) const {
size_t Size;
const detail::plugin &Plugin = getPlugin();
Plugin.call<PiApiKind::piProgramGetInfo>(MProgram, PI_PROGRAM_INFO_KERNEL_NAMES, 0,
nullptr, &Size);
Plugin.call<PiApiKind::piProgramGetInfo>(
MProgram, PI_PROGRAM_INFO_KERNEL_NAMES, 0, nullptr, &Size);
string_class ClResult(Size, ' ');
Plugin.call<PiApiKind::piProgramGetInfo>(MProgram, PI_PROGRAM_INFO_KERNEL_NAMES,
ClResult.size(), &ClResult[0],
nullptr);
Plugin.call<PiApiKind::piProgramGetInfo>(
MProgram, PI_PROGRAM_INFO_KERNEL_NAMES, ClResult.size(), &ClResult[0],
nullptr);
// Get rid of the null terminator
ClResult.pop_back();
vector_class<string_class> KernelNames(split_string(ClResult, ';'));
Expand Down Expand Up @@ -411,10 +412,11 @@ cl_uint program_impl::get_info<info::program::reference_count>() const {
throw invalid_object_error("This instance of program is a host instance",
PI_INVALID_PROGRAM);
}
cl_uint Result;
pi_uint32 Result;
const detail::plugin &Plugin = getPlugin();
Plugin.call<PiApiKind::piProgramGetInfo>(MProgram, PI_PROGRAM_INFO_REFERENCE_COUNT,
sizeof(cl_uint), &Result, nullptr);
Plugin.call<PiApiKind::piProgramGetInfo>(MProgram,
PI_PROGRAM_INFO_REFERENCE_COUNT,
sizeof(pi_uint32), &Result, nullptr);
return Result;
}

Expand Down
8 changes: 4 additions & 4 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static RT::PiProgram createBinaryProgram(const ContextImplPtr Context,
// FIXME: we don't yet support multiple devices with a single binary.
const detail::plugin &Plugin = Context->getPlugin();
#ifndef _NDEBUG
cl_uint NumDevices = 0;
pi_uint32 NumDevices = 0;
Plugin.call<PiApiKind::piContextGetInfo>(Context->getHandleRef(),
PI_CONTEXT_INFO_NUM_DEVICES,
sizeof(NumDevices), &NumDevices,
Expand Down Expand Up @@ -438,7 +438,7 @@ ProgramManager::getClProgramFromClKernel(RT::PiKernel Kernel,
RT::PiProgram Program;
const detail::plugin &Plugin = Context->getPlugin();
Plugin.call<PiApiKind::piKernelGetInfo>(
Kernel, PI_KERNEL_INFO_PROGRAM, sizeof(cl_program), &Program, nullptr);
Kernel, PI_KERNEL_INFO_PROGRAM, sizeof(RT::PiProgram), &Program, nullptr);
return Program;
}

Expand All @@ -449,8 +449,8 @@ string_class ProgramManager::getProgramBuildLog(const RT::PiProgram &Program,
Plugin.call<PiApiKind::piProgramGetInfo>(Program, PI_PROGRAM_INFO_DEVICES, 0,
nullptr, &Size);
vector_class<RT::PiDevice> PIDevices(Size / sizeof(RT::PiDevice));
Plugin.call<PiApiKind::piProgramGetInfo>(Program, PI_PROGRAM_INFO_DEVICES, Size,
PIDevices.data(), nullptr);
Plugin.call<PiApiKind::piProgramGetInfo>(Program, PI_PROGRAM_INFO_DEVICES,
Size, PIDevices.data(), nullptr);
string_class Log = "The program was built for " +
std::to_string(PIDevices.size()) + " devices";
for (RT::PiDevice &Device : PIDevices) {
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ event queue_impl::memcpy(shared_ptr_class<detail::queue_impl> Impl, void *Dest,
return ResEvent;
}

event queue_impl::mem_advise(const void *Ptr, size_t Length, int Advice) {
event queue_impl::mem_advise(const void *Ptr, size_t Length,
pi_mem_advice Advice) {
context Context = get_context();
if (Context.is_host()) {
return event();
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class queue_impl {
/// \param Ptr is a USM pointer to the allocation.
/// \param Length is a number of bytes in the allocation.
/// \param Advice is a device-defined advice for the specified allocation.
event mem_advise(const void *Ptr, size_t Length, int Advice);
event mem_advise(const void *Ptr, size_t Length, pi_mem_advice Advice);

/// Puts exception to the list of asynchronous ecxeptions.
///
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,11 +1643,11 @@ cl_int ExecCGCommand::enqueueImp() {
pi_mem MemArg = (pi_mem)AllocaCmd->getMemAllocation();
Plugin.call<PiApiKind::piextKernelSetArgMemObj>(Kernel, Arg.MIndex, &MemArg);
#else
cl_mem MemArg = (cl_mem)AllocaCmd->getMemAllocation();
RT::PiMem MemArg = (RT::PiMem)AllocaCmd->getMemAllocation();
Plugin.call<PiApiKind::piKernelSetArg>(Kernel, Arg.MIndex,
sizeof(cl_mem), &MemArg);
sizeof(RT::PiMem), &MemArg);
Plugin.call<PiApiKind::piKernelSetArg>(Kernel, Arg.MIndex,
sizeof(cl_mem), &MemArg);
sizeof(RT::PiMem), &MemArg);
#endif
break;
}
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ event queue::memcpy(void *dest, const void *src, size_t count) {
return impl->memcpy(impl, dest, src, count);
}

event queue::mem_advise(const void *ptr, size_t length, int advice) {
event queue::mem_advise(const void *ptr, size_t length, pi_mem_advice advice) {
return impl->mem_advise(ptr, length, advice);
}

Expand Down
4 changes: 2 additions & 2 deletions sycl/test/usm/memadvise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main() {
if (s_head == nullptr) {
return -1;
}
q.mem_advise(s_head, sizeof(Node), 42);
q.mem_advise(s_head, sizeof(Node), PI_MEM_ADVICE_SET_READ_MOSTLY);
Node *s_cur = s_head;

for (int i = 0; i < numNodes; i++) {
Expand All @@ -48,7 +48,7 @@ int main() {
if (s_cur->pNext == nullptr) {
return -1;
}
q.mem_advise(s_cur->pNext, sizeof(Node), 42);
q.mem_advise(s_cur->pNext, sizeof(Node), PI_MEM_ADVICE_SET_READ_MOSTLY);
} else {
s_cur->pNext = nullptr;
}
Expand Down