Skip to content

Commit fa3a6a9

Browse files
nrspruitomarahmed1111
authored andcommitted
[L0] Fix Get info Binaries And source and handle/pointer checks
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent 64ad451 commit fa3a6a9

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

source/adapters/level_zero/program.cpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL(
5858
*Program ///< [out] pointer to handle of program object created.
5959
) {
6060
std::ignore = Properties;
61+
UR_ASSERT(Context, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
62+
UR_ASSERT(IL && Program, UR_RESULT_ERROR_INVALID_NULL_POINTER);
6163
try {
6264
ur_program_handle_t_ *UrProgram =
6365
new ur_program_handle_t_(ur_program_handle_t_::IL, Context, IL, Length);
@@ -658,23 +660,34 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetInfo(
658660
// device. Since Level Zero supports only one device, there is only one
659661
// pointer. If the pointer is NULL, we don't do anything. Otherwise, we
660662
// copy the program's binary image to the buffer at that pointer.
663+
uint8_t **PBinary = nullptr;
661664
if (ProgramInfo) {
662-
uint8_t **PBinary = ur_cast<uint8_t **>(ProgramInfo);
663-
if (!PBinary[0])
665+
PBinary = ur_cast<uint8_t **>(ProgramInfo);
666+
if (!PBinary[0]) {
664667
break;
665-
666-
std::shared_lock<ur_shared_mutex> Guard(Program->Mutex);
667-
if (Program->State == ur_program_handle_t_::IL ||
668-
Program->State == ur_program_handle_t_::Native ||
669-
Program->State == ur_program_handle_t_::Object) {
668+
}
669+
}
670+
std::shared_lock<ur_shared_mutex> Guard(Program->Mutex);
671+
if (Program->State == ur_program_handle_t_::IL ||
672+
Program->State == ur_program_handle_t_::Native ||
673+
Program->State == ur_program_handle_t_::Object) {
674+
if (PropSizeRet)
675+
*PropSizeRet = Program->CodeLength;
676+
if (PBinary) {
670677
std::memcpy(PBinary[0], Program->Code.get(), Program->CodeLength);
671-
} else if (Program->State == ur_program_handle_t_::Exe) {
672-
size_t SzBinary = 0;
673-
ZE2UR_CALL(zeModuleGetNativeBinary,
674-
(Program->ZeModule, &SzBinary, PBinary[0]));
675-
} else {
676-
return UR_RESULT_ERROR_INVALID_PROGRAM;
677678
}
679+
} else if (Program->State == ur_program_handle_t_::Exe) {
680+
size_t SzBinary = 0;
681+
uint8_t *NativeBinaryPtr = nullptr;
682+
if (PBinary) {
683+
NativeBinaryPtr = PBinary[0];
684+
}
685+
ZE2UR_CALL(zeModuleGetNativeBinary,
686+
(Program->ZeModule, &SzBinary, NativeBinaryPtr));
687+
if (PropSizeRet)
688+
*PropSizeRet = SzBinary;
689+
} else {
690+
return UR_RESULT_ERROR_INVALID_PROGRAM;
678691
}
679692
break;
680693
}
@@ -723,7 +736,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetInfo(
723736
return UR_RESULT_ERROR_UNKNOWN;
724737
}
725738
case UR_PROGRAM_INFO_SOURCE:
726-
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
739+
return ReturnValue(Program->Code.get());
727740
default:
728741
return UR_RESULT_ERROR_INVALID_ENUMERATION;
729742
}
@@ -765,6 +778,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetBuildInfo(
765778
// return for programs that were built outside and registered
766779
// with urProgramRegister?
767780
return ReturnValue("");
781+
} else if (PropName == UR_PROGRAM_BUILD_INFO_STATUS) {
782+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
768783
} else if (PropName == UR_PROGRAM_BUILD_INFO_LOG) {
769784
// Check first to see if the plugin code recorded an error message.
770785
if (!Program->ErrorMessage.empty()) {
@@ -856,6 +871,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithNativeHandle(
856871
///< program object created.
857872
) {
858873
std::ignore = Properties;
874+
UR_ASSERT(Context && NativeProgram, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
875+
UR_ASSERT(Program, UR_RESULT_ERROR_INVALID_NULL_POINTER);
859876
auto ZeModule = ur_cast<ze_module_handle_t>(NativeProgram);
860877

861878
// We assume here that programs created from a native handle always

test/conformance/program/program_adapter_level_zero.match

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ urProgramCreateWithNativeHandleTest.InvalidNullHandleContext/Intel_R__oneAPI_Uni
33
urProgramCreateWithNativeHandleTest.InvalidNullPointerProgram/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
44
urProgramGetBuildInfoTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_PROGRAM_BUILD_INFO_STATUS
55
urProgramGetFunctionPointerTest.InvalidKernelName/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
6-
Aborted
6+
urProgramGetNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_

0 commit comments

Comments
 (0)