@@ -97,6 +97,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary(
9797 Program->URContext = hContext;
9898 Program->Binary = RealBinary;
9999 Program->BinarySizeInBytes = RealLength;
100+ Program->BinaryType = UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
100101
101102 // Parse properties
102103 if (pProperties) {
@@ -160,24 +161,68 @@ urProgramCreateWithIL(ur_context_handle_t hContext, const void *pIL,
160161}
161162
162163UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild (ur_context_handle_t ,
163- ur_program_handle_t ,
164- const char *) {
164+ ur_program_handle_t hProgram ,
165+ const char *pOptions ) {
165166 // Do nothing, program is built upon creation
167+ if (pOptions && *pOptions) {
168+ hProgram->Error = " Liboffload doesn't support link options" ;
169+ return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
170+ }
171+ hProgram->BinaryType = UR_PROGRAM_BINARY_TYPE_EXECUTABLE;
166172 return UR_RESULT_SUCCESS;
167173}
168174
169- UR_APIEXPORT ur_result_t UR_APICALL urProgramBuildExp (ur_program_handle_t ,
170- uint32_t ,
171- ur_device_handle_t *,
172- const char *) {
175+ UR_APIEXPORT ur_result_t UR_APICALL
176+ urProgramBuildExp (ur_program_handle_t hProgram, uint32_t , ur_device_handle_t *,
177+ const char *pOptions) {
173178 // Do nothing, program is built upon creation
179+ if (pOptions && *pOptions) {
180+ hProgram->Error = " Liboffload doesn't support link options" ;
181+ return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
182+ }
183+ hProgram->BinaryType = UR_PROGRAM_BINARY_TYPE_EXECUTABLE;
174184 return UR_RESULT_SUCCESS;
175185}
176186
177- UR_APIEXPORT ur_result_t UR_APICALL urProgramCompile (ur_context_handle_t ,
178- ur_program_handle_t ,
179- const char *) {
187+ UR_APIEXPORT ur_result_t UR_APICALL urProgramCompile (
188+ ur_context_handle_t , ur_program_handle_t hProgram, const char *pOptions) {
180189 // Do nothing, program is built upon creation
190+ if (pOptions && *pOptions) {
191+ hProgram->Error = " Liboffload doesn't support link options" ;
192+ return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
193+ }
194+ hProgram->BinaryType = UR_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
195+ return UR_RESULT_SUCCESS;
196+ }
197+
198+ UR_APIEXPORT ur_result_t UR_APICALL
199+ urProgramLink (ur_context_handle_t hContext, uint32_t count,
200+ const ur_program_handle_t *phPrograms, const char *pOptions,
201+ ur_program_handle_t *phProgram) {
202+ if (count > 1 ) {
203+ *phProgram = ur_program_handle_t_::newErrorProgram (
204+ hContext, nullptr , 0 ,
205+ " Liboffload does not support linking multiple binaries" );
206+ return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
207+ }
208+ if (pOptions) {
209+ *phProgram = ur_program_handle_t_::newErrorProgram (
210+ hContext, nullptr , 0 , " Liboffload does not support linker options" );
211+ return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
212+ }
213+ assert (count == 1 );
214+
215+ // Offload programs are already fully linked on creation, just create a new
216+ // program containing it
217+ auto *InProgram = *phPrograms;
218+ ur_program_handle_t Program = new ur_program_handle_t_{};
219+ Program->URContext = hContext;
220+ Program->Binary = InProgram->Binary ;
221+ Program->BinarySizeInBytes = InProgram->BinarySizeInBytes ;
222+ Program->GlobalIDMD = InProgram->GlobalIDMD ;
223+ Program->BinaryType = UR_PROGRAM_BINARY_TYPE_EXECUTABLE;
224+ *phProgram = Program;
225+
181226 return UR_RESULT_SUCCESS;
182227}
183228
@@ -230,6 +275,28 @@ urProgramGetInfo(ur_program_handle_t hProgram, ur_program_info_t propName,
230275 return UR_RESULT_SUCCESS;
231276}
232277
278+ UR_APIEXPORT ur_result_t UR_APICALL
279+ urProgramGetBuildInfo (ur_program_handle_t hProgram, ur_device_handle_t ,
280+ ur_program_build_info_t propName, size_t propSize,
281+ void *pPropValue, size_t *pPropSizeRet) {
282+ UrReturnHelper ReturnValue (propSize, pPropValue, pPropSizeRet);
283+ switch (propName) {
284+ case UR_PROGRAM_BUILD_INFO_STATUS:
285+ return ReturnValue (hProgram->Error .empty () ? UR_PROGRAM_BUILD_STATUS_SUCCESS
286+ : UR_PROGRAM_BUILD_STATUS_ERROR);
287+ case UR_PROGRAM_BUILD_INFO_OPTIONS:
288+ return ReturnValue (" " );
289+ case UR_PROGRAM_BUILD_INFO_LOG:
290+ return ReturnValue (hProgram->Error .c_str ());
291+ case UR_PROGRAM_BUILD_INFO_BINARY_TYPE:
292+ return ReturnValue (hProgram->BinaryType );
293+ default :
294+ return UR_RESULT_ERROR_INVALID_ENUMERATION;
295+ }
296+
297+ return UR_RESULT_SUCCESS;
298+ }
299+
233300UR_APIEXPORT ur_result_t UR_APICALL
234301urProgramRetain (ur_program_handle_t hProgram) {
235302 hProgram->RefCount ++;
@@ -239,11 +306,12 @@ urProgramRetain(ur_program_handle_t hProgram) {
239306UR_APIEXPORT ur_result_t UR_APICALL
240307urProgramRelease (ur_program_handle_t hProgram) {
241308 if (--hProgram->RefCount == 0 ) {
242- auto Res = olDestroyProgram (hProgram->OffloadProgram );
243- if (Res) {
244- return offloadResultToUR (Res);
309+ if (hProgram->OffloadProgram ) {
310+ if (auto Res = olDestroyProgram (hProgram->OffloadProgram )) {
311+ return offloadResultToUR (Res);
312+ }
313+ delete hProgram;
245314 }
246- delete hProgram;
247315 }
248316
249317 return UR_RESULT_SUCCESS;
0 commit comments