Skip to content

Commit 4584ea1

Browse files
align pi and ur api to use cast
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent e15e9eb commit 4584ea1

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

sycl/include/sycl/detail/pi.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,20 +1709,28 @@ __SYCL_EXPORT pi_result piEnqueueMemUnmap(pi_queue command_queue, pi_mem memobj,
17091709
const pi_event *event_wait_list,
17101710
pi_event *event);
17111711

1712+
#ifndef PI_BIT
1713+
#define PI_BIT(_i) (1 << _i)
1714+
#endif // PI_BIT
1715+
17121716
typedef enum {
1713-
PI_ACCESS_READ_WRITE,
1714-
PI_ACCESS_READ_ONLY,
1715-
PI_ACCESS_WRITE_ONLY
1717+
PI_ACCESS_READ_WRITE = PI_BIT(0),
1718+
PI_ACCESS_WRITE_ONLY = PI_BIT(1),
1719+
PI_ACCESS_READ_ONLY = PI_BIT(2)
17161720
} _pi_mem_obj_access;
17171721
using pi_mem_obj_access = _pi_mem_obj_access;
1722+
typedef uint32_t pi_mem_access_flag;
17181723

1719-
typedef enum { PI_KERNEL_ARG_MEM_OBJ_ACCESS } _pi_mem_obj_property_type;
1724+
typedef enum {
1725+
PI_KERNEL_ARG_MEM_OBJ_ACCESS = 29,
1726+
PI_ENUM_FORCE_UINT32 = 0x7fffffff
1727+
} _pi_mem_obj_property_type;
17201728
using pi_mem_obj_property_type = _pi_mem_obj_property_type;
17211729

17221730
typedef struct {
17231731
pi_mem_obj_property_type type;
17241732
void *pNext;
1725-
_pi_mem_obj_access mem_access;
1733+
pi_mem_access_flag mem_access;
17261734
} _pi_mem_obj_property;
17271735
using pi_mem_obj_property = _pi_mem_obj_property;
17281736

sycl/plugins/unified_runtime/pi2ur.hpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,23 +1926,33 @@ piextKernelSetArgMemObj(pi_kernel Kernel, pi_uint32 ArgIndex,
19261926
// to process it later when the device is known (at the kernel enqueue).
19271927
//
19281928
ur_kernel_handle_t UrKernel = reinterpret_cast<ur_kernel_handle_t>(Kernel);
1929-
if (ArgProperties) {
1930-
assert(ArgProperties->type == PI_KERNEL_ARG_MEM_OBJ_ACCESS);
1931-
ur_kernel_arg_mem_obj_properties_t UrMemProperties{};
1932-
UrMemProperties.stype = UR_STRUCTURE_TYPE_KERNEL_ARG_MEM_OBJ_PROPERTIES;
1933-
switch (ArgProperties->mem_access) {
1934-
case PI_ACCESS_READ_ONLY:
1935-
UrMemProperties.memoryAccess = UR_MEM_FLAG_READ_ONLY;
1936-
break;
1937-
case PI_ACCESS_WRITE_ONLY:
1938-
UrMemProperties.memoryAccess = UR_MEM_FLAG_WRITE_ONLY;
1939-
break;
1940-
case PI_ACCESS_READ_WRITE:
1941-
UrMemProperties.memoryAccess = UR_MEM_FLAG_READ_WRITE;
1942-
break;
1943-
}
1929+
// the only applicable type, just ignore anything else
1930+
if (ArgProperties && ArgProperties->type == PI_KERNEL_ARG_MEM_OBJ_ACCESS) {
1931+
// following structure layout checks to be replaced with
1932+
// std::is_layout_compatible after move to C++20
1933+
static_assert(sizeof(pi_mem_obj_property) ==
1934+
sizeof(ur_kernel_arg_mem_obj_properties_t));
1935+
static_assert(sizeof(pi_mem_obj_property::type) ==
1936+
sizeof(ur_kernel_arg_mem_obj_properties_t::stype));
1937+
static_assert(sizeof(pi_mem_obj_property::pNext) ==
1938+
sizeof(ur_kernel_arg_mem_obj_properties_t::pNext));
1939+
static_assert(sizeof(pi_mem_obj_property::mem_access) ==
1940+
sizeof(ur_kernel_arg_mem_obj_properties_t::memoryAccess));
1941+
1942+
static_assert(uint32_t(PI_ACCESS_READ_WRITE) ==
1943+
uint32_t(UR_MEM_FLAG_READ_WRITE));
1944+
static_assert(uint32_t(PI_ACCESS_READ_ONLY) ==
1945+
uint32_t(UR_MEM_FLAG_READ_ONLY));
1946+
static_assert(uint32_t(PI_ACCESS_WRITE_ONLY) ==
1947+
uint32_t(UR_MEM_FLAG_WRITE_ONLY));
1948+
static_assert(uint32_t(PI_KERNEL_ARG_MEM_OBJ_ACCESS) ==
1949+
uint32_t(UR_STRUCTURE_TYPE_KERNEL_ARG_MEM_OBJ_PROPERTIES));
1950+
1951+
const ur_kernel_arg_mem_obj_properties_t *UrMemProperties =
1952+
reinterpret_cast<const ur_kernel_arg_mem_obj_properties_t *>(
1953+
ArgProperties);
19441954
HANDLE_ERRORS(
1945-
urKernelSetArgMemObj(UrKernel, ArgIndex, &UrMemProperties, UrMemory));
1955+
urKernelSetArgMemObj(UrKernel, ArgIndex, UrMemProperties, UrMemory));
19461956
} else {
19471957
HANDLE_ERRORS(urKernelSetArgMemObj(UrKernel, ArgIndex, nullptr, UrMemory));
19481958
}

0 commit comments

Comments
 (0)