Skip to content

Commit

Permalink
Merge pull request #2223 from igchor/enqueue_usm
Browse files Browse the repository at this point in the history
Enable (almost) all conformance test on PVC for L0
  • Loading branch information
pbalcer authored Oct 30, 2024
2 parents d77ac05 + d654a17 commit 73e54a0
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/multi_device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ jobs:

- name: Test adapters
working-directory: ${{github.workspace}}/build
run: env UR_CTS_ADAPTER_PLATFORM="${{matrix.adapter.platform}}" ctest -C ${{matrix.build_type}} --output-on-failure -L "conformance" -E "enqueue|kernel|integration|exp_command_buffer|exp_enqueue_native|exp_launch_properties|exp_usm_p2p" --timeout 180
run: env UR_CTS_ADAPTER_PLATFORM="${{matrix.adapter.platform}}" ctest -C ${{matrix.build_type}} --output-on-failure -L "conformance" -E "exp_command_buffer" --timeout 180
1 change: 1 addition & 0 deletions source/adapters/level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ if(UR_BUILD_ADAPTER_L0_V2)
${CMAKE_CURRENT_SOURCE_DIR}/program.cpp
${CMAKE_CURRENT_SOURCE_DIR}/helpers/kernel_helpers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/helpers/memory_helpers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/usm_p2p.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
# v2-only sources
${CMAKE_CURRENT_SOURCE_DIR}/v2/command_list_cache.hpp
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/level_zero/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ uint64_t calculateGlobalMemSize(ur_device_handle_t Device) {
}
}
};
return Device->ZeGlobalMemSize.operator->()->value;
return Device->ZeGlobalMemSize.get().value;
}

ur_result_t urDeviceGetInfo(
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/level_zero/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ ur_result_t urKernelGetInfo(
return ReturnValue(ur_program_handle_t{Kernel->Program});
case UR_KERNEL_INFO_FUNCTION_NAME:
try {
std::string &KernelName = *Kernel->ZeKernelName.operator->();
std::string &KernelName = Kernel->ZeKernelName.get();
return ReturnValue(static_cast<const char *>(KernelName.c_str()));
} catch (const std::bad_alloc &) {
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
Expand Down
27 changes: 0 additions & 27 deletions source/adapters/level_zero/v2/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,6 @@ ur_result_t urPhysicalMemRelease(ur_physical_mem_handle_t hPhysicalMem) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

ur_result_t urKernelGetInfo(ur_kernel_handle_t hKernel,
ur_kernel_info_t propName, size_t propSize,
void *pPropValue, size_t *pPropSizeRet) {
logger::error("{} function not implemented!", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

ur_result_t
urKernelSetArgSampler(ur_kernel_handle_t hKernel, uint32_t argIndex,
const ur_kernel_arg_sampler_properties_t *pProperties,
Expand Down Expand Up @@ -629,24 +622,4 @@ ur_result_t urUSMReleaseExp(ur_context_handle_t hContext, void *pMem) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

ur_result_t urUsmP2PEnablePeerAccessExp(ur_device_handle_t commandDevice,
ur_device_handle_t peerDevice) {
logger::error("{} function not implemented!", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

ur_result_t urUsmP2PDisablePeerAccessExp(ur_device_handle_t commandDevice,
ur_device_handle_t peerDevice) {
logger::error("{} function not implemented!", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

ur_result_t urUsmP2PPeerAccessGetInfoExp(ur_device_handle_t commandDevice,
ur_device_handle_t peerDevice,
ur_exp_peer_info_t propName,
size_t propSize, void *pPropValue,
size_t *pPropSizeRet) {
logger::error("{} function not implemented!", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
} // namespace ur::level_zero
89 changes: 73 additions & 16 deletions source/adapters/level_zero/v2/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@ ur_result_t ur_kernel_handle_t_::release() {
void ur_kernel_handle_t_::completeInitialization() {
// Cache kernel name. Should be the same for all devices
assert(deviceKernels.size() > 0);
auto nonEmptyKernel =
std::find_if(deviceKernels.begin(), deviceKernels.end(),
[](const auto &kernel) { return kernel.has_value(); });
nonEmptyKernel =
&std::find_if(deviceKernels.begin(), deviceKernels.end(),
[](const auto &kernel) { return kernel.has_value(); })
->value();

zeKernelName.Compute = [kernel =
&nonEmptyKernel->value()](std::string &name) {
zeCommonProperties.Compute = [kernel = nonEmptyKernel](
common_properties_t &props) {
size_t size = 0;
ZE_CALL_NOCHECK(zeKernelGetName, (kernel->hKernel.get(), &size, nullptr));
name.resize(size);
props.name.resize(size);
ZE_CALL_NOCHECK(zeKernelGetName,
(kernel->hKernel.get(), &size, name.data()));
(kernel->hKernel.get(), &size, props.name.data()));
props.numKernelArgs = kernel->zeKernelProperties->numKernelArgs;
};
}

Expand Down Expand Up @@ -142,8 +144,9 @@ ur_kernel_handle_t_::getZeHandle(ur_device_handle_t hDevice) {
return deviceKernels[hDevice->Id.value()].value().hKernel.get();
}

const std::string &ur_kernel_handle_t_::getName() const {
return *zeKernelName.operator->();
ur_kernel_handle_t_::common_properties_t
ur_kernel_handle_t_::getCommonProperties() const {
return zeCommonProperties.get();
}

const ze_kernel_properties_t &
Expand All @@ -154,10 +157,7 @@ ur_kernel_handle_t_::getProperties(ur_device_handle_t hDevice) const {

assert(deviceKernels[hDevice->Id.value()].value().hKernel.get());

return *deviceKernels[hDevice->Id.value()]
.value()
.zeKernelProperties.
operator->();
return deviceKernels[hDevice->Id.value()].value().zeKernelProperties.get();
}

ur_result_t ur_kernel_handle_t_::setArgValue(
Expand All @@ -178,16 +178,26 @@ ur_result_t ur_kernel_handle_t_::setArgValue(
pArgValue = nullptr;
}

if (argIndex > zeCommonProperties->numKernelArgs - 1) {
return UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX;
}

std::scoped_lock<ur_shared_mutex> guard(Mutex);

for (auto &singleDeviceKernel : deviceKernels) {
if (!singleDeviceKernel.has_value()) {
continue;
}

ZE2UR_CALL(zeKernelSetArgumentValue,
(singleDeviceKernel.value().hKernel.get(), argIndex, argSize,
pArgValue));
auto zeResult = ZE_CALL_NOCHECK(zeKernelSetArgumentValue,
(singleDeviceKernel.value().hKernel.get(),
argIndex, argSize, pArgValue));

if (zeResult == ZE_RESULT_ERROR_INVALID_ARGUMENT) {
return UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE;
} else if (zeResult != ZE_RESULT_SUCCESS) {
return ze2urResult(zeResult);
}
}
return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -257,6 +267,17 @@ std::vector<ur_device_handle_t> ur_kernel_handle_t_::getDevices() const {
return devices;
}

std::vector<char> ur_kernel_handle_t_::getSourceAttributes() const {
uint32_t size;
ZE2UR_CALL_THROWS(zeKernelGetSourceAttributes,
(nonEmptyKernel->hKernel.get(), &size, nullptr));
std::vector<char> attributes(size);
char *dataPtr = attributes.data();
ZE2UR_CALL_THROWS(zeKernelGetSourceAttributes,
(nonEmptyKernel->hKernel.get(), &size, &dataPtr));
return attributes;
}

namespace ur::level_zero {
ur_result_t urKernelCreate(ur_program_handle_t hProgram,
const char *pKernelName,
Expand Down Expand Up @@ -477,4 +498,40 @@ ur_result_t urKernelGetSubGroupInfo(
}
return UR_RESULT_SUCCESS;
}

ur_result_t urKernelGetInfo(ur_kernel_handle_t hKernel,
ur_kernel_info_t paramName, size_t propSize,
void *pKernelInfo, size_t *pPropSizeRet) {

UrReturnHelper ReturnValue(propSize, pKernelInfo, pPropSizeRet);

std::shared_lock<ur_shared_mutex> Guard(hKernel->Mutex);
switch (paramName) {
case UR_KERNEL_INFO_CONTEXT:
return ReturnValue(
ur_context_handle_t{hKernel->getProgramHandle()->Context});
case UR_KERNEL_INFO_PROGRAM:
return ReturnValue(ur_program_handle_t{hKernel->getProgramHandle()});
case UR_KERNEL_INFO_FUNCTION_NAME: {
auto kernelName = hKernel->getCommonProperties().name;
return ReturnValue(static_cast<const char *>(kernelName.c_str()));
}
case UR_KERNEL_INFO_NUM_REGS:
case UR_KERNEL_INFO_NUM_ARGS:
return ReturnValue(uint32_t{hKernel->getCommonProperties().numKernelArgs});
case UR_KERNEL_INFO_REFERENCE_COUNT:
return ReturnValue(uint32_t{hKernel->RefCount.load()});
case UR_KERNEL_INFO_ATTRIBUTES: {
auto attributes = hKernel->getSourceAttributes();
return ReturnValue(static_cast<const char *>(attributes.data()));
}
default:
logger::error(
"Unsupported ParamName in urKernelGetInfo: ParamName={}(0x{})",
paramName, logger::toHex(paramName));
return UR_RESULT_ERROR_INVALID_VALUE;
}

return UR_RESULT_SUCCESS;
}
} // namespace ur::level_zero
16 changes: 13 additions & 3 deletions source/adapters/level_zero/v2/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ struct ur_single_device_kernel_t {
struct ur_kernel_handle_t_ : _ur_object {
private:
public:
struct common_properties_t {
std::string name;
uint32_t numKernelArgs;
};

ur_kernel_handle_t_(ur_program_handle_t hProgram, const char *kernelName);

// From native handle
Expand All @@ -44,7 +49,7 @@ struct ur_kernel_handle_t_ : _ur_object {
std::vector<ur_device_handle_t> getDevices() const;

// Get name of the kernel.
const std::string &getName() const;
common_properties_t getCommonProperties() const;

// Get properties of the kernel.
const ze_kernel_properties_t &getProperties(ur_device_handle_t hDevice) const;
Expand All @@ -64,6 +69,8 @@ struct ur_kernel_handle_t_ : _ur_object {
ur_result_t setExecInfo(ur_kernel_exec_info_t propName,
const void *pPropValue);

std::vector<char> getSourceAttributes() const;

// Perform cleanup.
ur_result_t release();

Expand All @@ -74,8 +81,11 @@ struct ur_kernel_handle_t_ : _ur_object {
// Vector of ur_single_device_kernel_t indexed by device->Id
std::vector<std::optional<ur_single_device_kernel_t>> deviceKernels;

// Cache of the kernel name.
mutable ZeCache<std::string> zeKernelName;
// Cache of the common kernel properties.
mutable ZeCache<common_properties_t> zeCommonProperties;

void completeInitialization();

// pointer to any non-null kernel in deviceKernels
ur_single_device_kernel_t *nonEmptyKernel;
};
8 changes: 5 additions & 3 deletions source/ur/ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,13 @@ template <class T> struct ZeCache : private T {

ZeCache() : T{} {}

// Access to the fields of the original T data structure.
T *operator->() {
T &get() {
std::call_once(Computed, Compute, static_cast<T &>(*this));
return this;
return *this;
}

// Access to the fields of the original T data structure.
T *operator->() { return &get(); }
};

// Helper for one-liner validation
Expand Down
71 changes: 36 additions & 35 deletions test/conformance/enqueue/enqueue_adapter_level_zero.match
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{{OPT}}urEnqueueKernelLaunchTest.InvalidKernelArgs/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
{{OPT}}urEnqueueKernelLaunchKernelWgSizeTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
{{OPT}}urEnqueueKernelLaunchKernelSubGroupTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
{{OPT}}urEnqueueKernelLaunchUSMLinkedList.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}__UsePoolEnabled
{{OPT}}urEnqueueKernelLaunchUSMLinkedList.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}__UsePoolDisabled
{{OPT}}urEnqueueMemBufferCopyRectTestWithParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___copy_2d_3d
{{OPT}}urEnqueueMemBufferCopyRectTestWithParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___copy_3d_2d
{{OPT}}urEnqueueMemBufferReadRectTestWithParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___write_non_zero_offsets_2D
Expand All @@ -13,6 +11,7 @@
{{OPT}}urEnqueueMemBufferReadRectTestWithParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___write_3d_with_offsets
{{OPT}}urEnqueueMemBufferReadRectTestWithParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___write_2d_3d
{{OPT}}urEnqueueMemBufferReadRectTestWithParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___write_3d_2d
{{OPT}}urEnqueueMemBufferMapMultiDeviceTest.*
{{OPT}}urEnqueueMemBufferWriteRectTestWithParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___write_3d_with_offsets
{{OPT}}urEnqueueMemBufferWriteRectTestWithParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___write_2d_3d
{{OPT}}urEnqueueMemBufferWriteRectTestWithParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___write_3d_2d
Expand All @@ -23,46 +22,48 @@
{{OPT}}urEnqueueMemImageReadTest.InvalidOrigin2D/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
{{OPT}}urEnqueueMemImageReadTest.InvalidOrigin3D/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
{{OPT}}urEnqueueEventsWaitMultiDeviceMTTest/*
urEnqueueEventsWaitWithBarrierOrderingTest.SuccessEventDependencies/*
urEnqueueEventsWaitWithBarrierOrderingTest.SuccessEventDependenciesBarrierOnly/*
urEnqueueEventsWaitWithBarrierOrderingTest.SuccessEventDependenciesLaunchOnly/*
urEnqueueEventsWaitWithBarrierOrderingTest.SuccessNonEventDependencies/*
urEnqueueEventsWaitWithBarrierTest.Success/*
urEnqueueMemBufferCopyRectTestWithParam.Success/*
urEnqueueMemBufferCopyTestWithParam.Success/*
urEnqueueMemBufferFillTest.Success/*
urEnqueueMemBufferFillTest.SuccessOffset/*
urEnqueueMemBufferFillTest.SuccessPartialFill/*
urEnqueueMemBufferMapTestWithParam.SuccesPinnedWrite/*
urEnqueueMemBufferMapTestWithParam.SuccessMultiMaps/*
urEnqueueMemBufferMapTestWithParam.SuccessOffset/*
urEnqueueMemBufferMapTestWithParam.SuccessPartialMap/*
urEnqueueMemBufferMapTestWithWriteFlagParam.SuccessWrite/*
urEnqueueMemBufferReadRectTestWithParam.Success/*
urEnqueueMemBufferWriteRectTestWithParam.Success/*
urEnqueueMemImageCopyTest.Success/*
urEnqueueMemImageCopyTest.SuccessPartialCopy/*
urEnqueueMemImageCopyTest.SuccessPartialCopyWithDstOffset/*
urEnqueueMemImageCopyTest.SuccessPartialCopyWithSrcOffset/*
urEnqueueMemImageReadTest.InvalidRegion1D/*
urEnqueueMemImageReadTest.InvalidRegion2D/*
urEnqueueMemImageReadTest.InvalidRegion3D/*
urEnqueueMemImageWriteTest.InvalidOrigin1D/*
urEnqueueMemImageWriteTest.InvalidOrigin2D/*
urEnqueueMemImageWriteTest.InvalidOrigin3D/*
urEnqueueMemImageWriteTest.InvalidRegion1D/*
urEnqueueMemImageWriteTest.InvalidRegion2D/*
urEnqueueMemImageWriteTest.InvalidRegion3D/*
{{OPT}}urEnqueueEventsWaitWithBarrierOrderingTest.SuccessEventDependencies/*
{{OPT}}urEnqueueEventsWaitWithBarrierOrderingTest.SuccessEventDependenciesBarrierOnly/*
{{OPT}}urEnqueueEventsWaitWithBarrierOrderingTest.SuccessEventDependenciesLaunchOnly/*
{{OPT}}urEnqueueEventsWaitWithBarrierOrderingTest.SuccessNonEventDependencies/*
{{OPT}}urEnqueueEventsWaitWithBarrierTest.Success/*
{{OPT}}urEnqueueMemBufferCopyRectTestWithParam.Success/*
{{OPT}}urEnqueueMemBufferCopyTestWithParam.Success/*
{{OPT}}urEnqueueMemBufferFillTest.Success/*
{{OPT}}urEnqueueMemBufferFillTest.SuccessOffset/*
{{OPT}}urEnqueueMemBufferFillTest.SuccessPartialFill/*
{{OPT}}urEnqueueMemBufferMapTestWithParam.SuccesPinnedWrite/*
{{OPT}}urEnqueueMemBufferMapTestWithParam.SuccessMultiMaps/*
{{OPT}}urEnqueueMemBufferMapTestWithParam.SuccessRead/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___Intel_R__Data_Center_GPU_Max*
{{OPT}}urEnqueueMemBufferMapTestWithParam.SuccessOffset/*
{{OPT}}urEnqueueMemBufferMapTestWithParam.SuccessPartialMap/*
{{OPT}}urEnqueueMemBufferMapTestWithWriteFlagParam.SuccessWrite/*
{{OPT}}urEnqueueMemBufferReadRectTestWithParam.Success/*
{{OPT}}urEnqueueMemBufferWriteRectTestWithParam.Success/*
{{OPT}}urEnqueueMemImageCopyTest.Success/*
{{OPT}}urEnqueueMemImageCopyTest.SuccessPartialCopy/*
{{OPT}}urEnqueueMemImageCopyTest.SuccessPartialCopyWithDstOffset/*
{{OPT}}urEnqueueMemImageCopyTest.SuccessPartialCopyWithSrcOffset/*
{{OPT}}urEnqueueMemImageReadTest.InvalidRegion1D/*
{{OPT}}urEnqueueMemImageReadTest.InvalidRegion2D/*
{{OPT}}urEnqueueMemImageReadTest.InvalidRegion3D/*
{{OPT}}urEnqueueMemImageWriteTest.InvalidOrigin1D/*
{{OPT}}urEnqueueMemImageWriteTest.InvalidOrigin2D/*
{{OPT}}urEnqueueMemImageWriteTest.InvalidOrigin3D/*
{{OPT}}urEnqueueMemImageWriteTest.InvalidRegion1D/*
{{OPT}}urEnqueueMemImageWriteTest.InvalidRegion2D/*
{{OPT}}urEnqueueMemImageWriteTest.InvalidRegion3D/*
{{OPT}}urEnqueueKernelLaunchMultiDeviceTest.KernelLaunchReadDifferentQueues/*
urEnqueueReadHostPipeTest.InvalidEventWaitList/*
urEnqueueReadHostPipeTest.InvalidNullHandleProgram/*
urEnqueueReadHostPipeTest.InvalidNullHandleQueue/*
urEnqueueReadHostPipeTest.InvalidNullPointerBuffer/*
urEnqueueReadHostPipeTest.InvalidNullPointerPipeSymbol/*
urEnqueueUSMAdviseTest.InvalidSizeTooLarge/*
urEnqueueUSMFill2DNegativeTest.OutOfBounds/*
urEnqueueUSMMemcpyTest.Blocking/*
urEnqueueUSMMemcpyTest.BlockingWithEvent/*
urEnqueueUSMMemcpyTest.WaitForDependencies/*
{{OPT}}urEnqueueUSMMemcpyTest.Blocking/*
{{OPT}}urEnqueueUSMMemcpyTest.BlockingWithEvent/*
{{OPT}}urEnqueueUSMMemcpyTest.WaitForDependencies/*
urEnqueueUSMPrefetchTest.InvalidSizeTooLarge/*
urEnqueueWriteHostPipeTest.InvalidEventWaitList/*
urEnqueueWriteHostPipeTest.InvalidNullHandleProgram/*
Expand Down
Loading

0 comments on commit 73e54a0

Please sign in to comment.