Skip to content

Commit 584869e

Browse files
committed
Change urProgramCreateWithBinary signature in adapters
1 parent c838a67 commit 584869e

File tree

10 files changed

+76
-92
lines changed

10 files changed

+76
-92
lines changed

source/adapters/cuda/program.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,23 +483,23 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetNativeHandle(
483483
}
484484

485485
UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary(
486-
ur_context_handle_t hContext, ur_device_handle_t hDevice, size_t size,
487-
const uint8_t *pBinary, const ur_program_properties_t *pProperties,
486+
ur_context_handle_t hContext, uint32_t numDevices,
487+
ur_device_handle_t *phDevices, size_t *pLengths, const uint8_t **ppBinaries,
488+
const ur_program_properties_t *pProperties,
488489
ur_program_handle_t *phProgram) {
490+
if (numDevices > 1)
491+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
489492

490-
UR_CHECK_ERROR(
491-
createProgram(hContext, hDevice, size, pBinary, pProperties, phProgram));
493+
if (numDevices == 0)
494+
return UR_RESULT_ERROR_INVALID_DEVICE;
495+
496+
UR_CHECK_ERROR(createProgram(hContext, phDevices[0], pLengths[0],
497+
ppBinaries[0], pProperties, phProgram));
492498
(*phProgram)->BinaryType = UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
493499

494500
return UR_RESULT_SUCCESS;
495501
}
496502

497-
UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinaryExp(
498-
ur_context_handle_t, uint32_t, ur_device_handle_t *, size_t *,
499-
const uint8_t **, const ur_program_properties_t *, ur_program_handle_t *) {
500-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
501-
}
502-
503503
// This entry point is only used for native specialization constants (SPIR-V),
504504
// and the CUDA plugin is AOT only so this entry point is not supported.
505505
UR_APIEXPORT ur_result_t UR_APICALL urProgramSetSpecializationConstants(

source/adapters/cuda/ur_interface_loader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramExpProcAddrTable(
442442
pDdiTable->pfnBuildExp = urProgramBuildExp;
443443
pDdiTable->pfnCompileExp = urProgramCompileExp;
444444
pDdiTable->pfnLinkExp = urProgramLinkExp;
445-
pDdiTable->pfnCreateWithBinaryExp = urProgramCreateWithBinaryExp;
446445

447446
return UR_RESULT_SUCCESS;
448447
}

source/adapters/hip/program.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetNativeHandle(
480480
///
481481
/// Note: Only supports one device
482482
UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary(
483-
ur_context_handle_t hContext, ur_device_handle_t hDevice, size_t size,
484-
const uint8_t *pBinary, const ur_program_properties_t *pProperties,
483+
ur_context_handle_t hContext, uint32_t numDevices,
484+
ur_device_handle_t *phDevices, size_t *pLengths, const uint8_t **ppBinaries,
485+
const ur_program_properties_t *pProperties,
485486
ur_program_handle_t *phProgram) {
487+
if (numDevices > 1)
488+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
489+
490+
if (numDevices == 0)
491+
return UR_RESULT_ERROR_INVALID_DEVICE;
492+
493+
auto hDevice = phDevices[0];
494+
auto pBinary = ppBinaries[0];
495+
auto size = pLengths[0];
486496
UR_ASSERT(std::find(hContext->getDevices().begin(),
487497
hContext->getDevices().end(),
488498
hDevice) != hContext->getDevices().end(),
@@ -522,12 +532,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary(
522532
return UR_RESULT_SUCCESS;
523533
}
524534

525-
UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinaryExp(
526-
ur_context_handle_t, uint32_t, ur_device_handle_t *, size_t *,
527-
const uint8_t **, const ur_program_properties_t *, ur_program_handle_t *) {
528-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
529-
}
530-
531535
// This entry point is only used for native specialization constants (SPIR-V),
532536
// and the HIP plugin is AOT only so this entry point is not supported.
533537
UR_APIEXPORT ur_result_t UR_APICALL urProgramSetSpecializationConstants(

source/adapters/hip/ur_interface_loader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramExpProcAddrTable(
407407
pDdiTable->pfnBuildExp = urProgramBuildExp;
408408
pDdiTable->pfnCompileExp = urProgramCompileExp;
409409
pDdiTable->pfnLinkExp = urProgramLinkExp;
410-
pDdiTable->pfnCreateWithBinaryExp = urProgramCreateWithBinaryExp;
411410

412411
return UR_RESULT_SUCCESS;
413412
}

source/adapters/level_zero/program.cpp

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,42 +83,6 @@ ur_result_t urProgramCreateWithIL(
8383
}
8484

8585
ur_result_t urProgramCreateWithBinary(
86-
ur_context_handle_t Context, ///< [in] handle of the context instance
87-
ur_device_handle_t
88-
Device, ///< [in] handle to device associated with binary.
89-
size_t Size, ///< [in] size in bytes.
90-
const uint8_t *Binary, ///< [in] pointer to binary.
91-
const ur_program_properties_t
92-
*Properties, ///< [in][optional] pointer to program creation properties.
93-
ur_program_handle_t
94-
*Program ///< [out] pointer to handle of Program object created.
95-
) {
96-
// In OpenCL, clCreateProgramWithBinary() can be used to load any of the
97-
// following: "program executable", "compiled program", or "library of
98-
// compiled programs". In addition, the loaded program can be either
99-
// IL (SPIR-v) or native device code. For now, we assume that
100-
// urProgramCreateWithBinary() is only used to load a "program executable"
101-
// as native device code.
102-
// If we wanted to support all the same cases as OpenCL, we would need to
103-
// somehow examine the binary image to distinguish the cases. Alternatively,
104-
// we could change the PI interface and have the caller pass additional
105-
// information to distinguish the cases.
106-
107-
try {
108-
ur_program_handle_t_ *UrProgram =
109-
new ur_program_handle_t_(ur_program_handle_t_::Native, Context, 1,
110-
&Device, Properties, &Binary, &Size);
111-
*Program = reinterpret_cast<ur_program_handle_t>(UrProgram);
112-
} catch (const std::bad_alloc &) {
113-
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
114-
} catch (...) {
115-
return UR_RESULT_ERROR_UNKNOWN;
116-
}
117-
118-
return UR_RESULT_SUCCESS;
119-
}
120-
121-
ur_result_t urProgramCreateWithBinaryExp(
12286
ur_context_handle_t hContext, ///< [in] handle of the context instance
12387
uint32_t numDevices, ///< [in] number of devices
12488
ur_device_handle_t
@@ -135,6 +99,16 @@ ur_result_t urProgramCreateWithBinaryExp(
13599
ur_program_handle_t
136100
*phProgram ///< [out] pointer to handle of Program object created.
137101
) {
102+
// In OpenCL, clCreateProgramWithBinary() can be used to load any of the
103+
// following: "program executable", "compiled program", or "library of
104+
// compiled programs". In addition, the loaded program can be either
105+
// IL (SPIR-v) or native device code. For now, we assume that
106+
// urProgramCreateWithBinary() is only used to load a "program executable"
107+
// as native device code.
108+
// If we wanted to support all the same cases as OpenCL, we would need to
109+
// somehow examine the binary image to distinguish the cases. Alternatively,
110+
// we could change the PI interface and have the caller pass additional
111+
// information to distinguish the cases.
138112
try {
139113
ur_program_handle_t_ *UrProgram = new ur_program_handle_t_(
140114
ur_program_handle_t_::Native, hContext, numDevices, phDevices,

source/adapters/native_cpu/program.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,19 @@ deserializeWGMetadata(const ur_program_metadata_t &MetadataElement,
5454
}
5555

5656
UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary(
57-
ur_context_handle_t hContext, ur_device_handle_t hDevice, size_t size,
58-
const uint8_t *pBinary, const ur_program_properties_t *pProperties,
57+
ur_context_handle_t hContext, uint32_t numDevices,
58+
ur_device_handle_t *phDevices, size_t *pLengths, const uint8_t **ppBinaries,
59+
const ur_program_properties_t *pProperties,
5960
ur_program_handle_t *phProgram) {
60-
std::ignore = size;
61+
if (numDevices > 1)
62+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
63+
64+
if (numDevices == 0)
65+
return UR_RESULT_ERROR_INVALID_DEVICE;
66+
67+
auto hDevice = phDevices[0];
68+
auto pBinary = ppBinaries[0];
69+
std::ignore = pLengths;
6170
std::ignore = pProperties;
6271

6372
UR_ASSERT(hContext, UR_RESULT_ERROR_INVALID_NULL_HANDLE);

source/adapters/native_cpu/ur_interface_loader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramExpProcAddrTable(
425425
pDdiTable->pfnBuildExp = urProgramBuildExp;
426426
pDdiTable->pfnCompileExp = urProgramCompileExp;
427427
pDdiTable->pfnLinkExp = urProgramLinkExp;
428-
pDdiTable->pfnCreateWithBinaryExp = urProgramCreateWithBinaryExp;
429428

430429
return UR_RESULT_SUCCESS;
431430
}

source/adapters/opencl/program.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,24 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL(
116116
}
117117

118118
UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary(
119-
ur_context_handle_t hContext, ur_device_handle_t hDevice, size_t size,
120-
const uint8_t *pBinary, const ur_program_properties_t *,
119+
ur_context_handle_t hContext, uint32_t numDevices,
120+
ur_device_handle_t *phDevices, size_t *pLengths, const uint8_t **ppBinaries,
121+
const ur_program_properties_t *pProperties,
121122
ur_program_handle_t *phProgram) {
122-
123-
const cl_device_id Devices[1] = {cl_adapter::cast<cl_device_id>(hDevice)};
124-
const size_t Lengths[1] = {size};
125-
cl_int BinaryStatus[1];
123+
cl_device_id Devices[numDevices];
124+
for (uint32_t i = 0; i < numDevices; ++i)
125+
Devices[i] = cl_adapter::cast<cl_device_id>(phDevices[i]);
126+
cl_int BinaryStatus[numDevices];
126127
cl_int CLResult;
127128
*phProgram = cl_adapter::cast<ur_program_handle_t>(clCreateProgramWithBinary(
128129
cl_adapter::cast<cl_context>(hContext), cl_adapter::cast<cl_uint>(1u),
129-
Devices, Lengths, &pBinary, BinaryStatus, &CLResult));
130+
Devices, pLengths, ppBinaries, BinaryStatus, &CLResult));
130131
CL_RETURN_ON_FAILURE(BinaryStatus[0]);
131132
CL_RETURN_ON_FAILURE(CLResult);
132133

133134
return UR_RESULT_SUCCESS;
134135
}
135136

136-
UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinaryExp(
137-
ur_context_handle_t, uint32_t, ur_device_handle_t *, size_t *,
138-
const uint8_t **, const ur_program_properties_t *, ur_program_handle_t *) {
139-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
140-
}
141-
142137
UR_APIEXPORT ur_result_t UR_APICALL
143138
urProgramCompile([[maybe_unused]] ur_context_handle_t hContext,
144139
ur_program_handle_t hProgram, const char *pOptions) {

source/adapters/opencl/ur_interface_loader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetProgramExpProcAddrTable(
432432
pDdiTable->pfnBuildExp = urProgramBuildExp;
433433
pDdiTable->pfnCompileExp = urProgramCompileExp;
434434
pDdiTable->pfnLinkExp = urProgramLinkExp;
435-
pDdiTable->pfnCreateWithBinaryExp = urProgramCreateWithBinaryExp;
436435

437436
return UR_RESULT_SUCCESS;
438437
}

test/adapters/cuda/kernel_tests.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ const char *threeParamsTwoLocal = "\n\
7474
TEST_P(cudaKernelTest, CreateProgramAndKernel) {
7575

7676
uur::raii::Program program = nullptr;
77-
ASSERT_SUCCESS(urProgramCreateWithBinary(
78-
context, device, std::strlen(ptxSource), (const uint8_t *)ptxSource,
79-
nullptr, program.ptr()));
77+
auto Length = std::strlen(ptxSource);
78+
ASSERT_SUCCESS(urProgramCreateWithBinary(context, 1, &device, &Length,
79+
(const uint8_t **)(&ptxSource),
80+
nullptr, program.ptr()));
8081
ASSERT_NE(program, nullptr);
8182
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
8283

@@ -116,9 +117,10 @@ TEST_P(cudaKernelTest, CreateProgramAndKernelWithMetadata) {
116117
ur_program_properties_t programProps{UR_STRUCTURE_TYPE_PROGRAM_PROPERTIES,
117118
nullptr, 1, &reqdWorkGroupSizeMDProp};
118119
uur::raii::Program program = nullptr;
119-
ASSERT_SUCCESS(urProgramCreateWithBinary(
120-
context, device, std::strlen(ptxSource), (const uint8_t *)ptxSource,
121-
&programProps, program.ptr()));
120+
auto Length = std::strlen(ptxSource);
121+
ASSERT_SUCCESS(urProgramCreateWithBinary(context, 1, &device, &Length,
122+
(const uint8_t **)(&ptxSource),
123+
&programProps, program.ptr()));
122124
ASSERT_NE(program, nullptr);
123125

124126
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
@@ -138,9 +140,10 @@ TEST_P(cudaKernelTest, CreateProgramAndKernelWithMetadata) {
138140

139141
TEST_P(cudaKernelTest, URKernelArgumentSimple) {
140142
uur::raii::Program program = nullptr;
141-
ASSERT_SUCCESS(urProgramCreateWithBinary(
142-
context, device, std::strlen(ptxSource), (const uint8_t *)ptxSource,
143-
nullptr, program.ptr()));
143+
auto Length = std::strlen(ptxSource);
144+
ASSERT_SUCCESS(urProgramCreateWithBinary(context, 1, &device, &Length,
145+
(const uint8_t **)(&ptxSource),
146+
nullptr, program.ptr()));
144147
ASSERT_NE(program, nullptr);
145148
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
146149

@@ -160,9 +163,10 @@ TEST_P(cudaKernelTest, URKernelArgumentSimple) {
160163

161164
TEST_P(cudaKernelTest, URKernelArgumentSetTwice) {
162165
uur::raii::Program program = nullptr;
163-
ASSERT_SUCCESS(urProgramCreateWithBinary(
164-
context, device, std::strlen(ptxSource), (const uint8_t *)ptxSource,
165-
nullptr, program.ptr()));
166+
auto Length = std::strlen(ptxSource);
167+
ASSERT_SUCCESS(urProgramCreateWithBinary(context, 1, &device, &Length,
168+
(const uint8_t **)(&ptxSource),
169+
nullptr, program.ptr()));
166170
ASSERT_NE(program, nullptr);
167171
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
168172

@@ -189,9 +193,10 @@ TEST_P(cudaKernelTest, URKernelArgumentSetTwice) {
189193

190194
TEST_P(cudaKernelTest, URKernelDispatch) {
191195
uur::raii::Program program = nullptr;
192-
ASSERT_SUCCESS(urProgramCreateWithBinary(
193-
context, device, std::strlen(ptxSource), (const uint8_t *)ptxSource,
194-
nullptr, program.ptr()));
196+
auto Length = std::strlen(ptxSource);
197+
ASSERT_SUCCESS(urProgramCreateWithBinary(context, 1, &device, &Length,
198+
(const uint8_t **)(&ptxSource),
199+
nullptr, program.ptr()));
195200
ASSERT_NE(program, nullptr);
196201
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
197202

@@ -218,9 +223,10 @@ TEST_P(cudaKernelTest, URKernelDispatch) {
218223

219224
TEST_P(cudaKernelTest, URKernelDispatchTwo) {
220225
uur::raii::Program program = nullptr;
221-
ASSERT_SUCCESS(urProgramCreateWithBinary(
222-
context, device, std::strlen(ptxSource), (const uint8_t *)twoParams,
223-
nullptr, program.ptr()));
226+
auto Length = std::strlen(ptxSource);
227+
ASSERT_SUCCESS(urProgramCreateWithBinary(context, 1, &device, &Length,
228+
(const uint8_t **)(&twoParams),
229+
nullptr, program.ptr()));
224230
ASSERT_NE(program, nullptr);
225231
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
226232

0 commit comments

Comments
 (0)