Skip to content

Commit

Permalink
Tidy and move common adapter code to ur_common
Browse files Browse the repository at this point in the history
  • Loading branch information
callumfare committed Oct 26, 2023
1 parent cf26de2 commit ac29419
Show file tree
Hide file tree
Showing 78 changed files with 660 additions and 603 deletions.
6 changes: 0 additions & 6 deletions source/adapters/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ add_ur_adapter(${TARGET_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/tracing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/usm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/usm_p2p.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.hpp
)

set_target_properties(${TARGET_NAME} PROPERTIES
Expand Down Expand Up @@ -82,7 +80,3 @@ target_link_libraries(${TARGET_NAME} PRIVATE
Threads::Threads
cudadrv
)

target_include_directories(${TARGET_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../"
)
3 changes: 2 additions & 1 deletion source/adapters/cuda/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
size_t propSize,
void *pPropValue,
size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

switch (propName) {
case UR_ADAPTER_INFO_BACKEND:
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
//===----------------------------------------------------------------------===//

#include <ur/ur.hpp>
#include <ur_api.h>

/// Stub implementation of command-buffers for CUDA

Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#pragma once

#include <cuda.h>
#include <ur/ur.hpp>
#include <ur_adapter_util.hpp>

ur_result_t mapErrorUR(CUresult Result);

Expand Down
3 changes: 2 additions & 1 deletion source/adapters/cuda/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ urContextCreate(uint32_t DeviceCount, const ur_device_handle_t *phDevices,
UR_APIEXPORT ur_result_t UR_APICALL urContextGetInfo(
ur_context_handle_t hContext, ur_context_info_t ContextInfoType,
size_t propSize, void *pContextInfo, size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pContextInfo, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pContextInfo,
pPropSizeRet);

switch (static_cast<uint32_t>(ContextInfoType)) {
case UR_CONTEXT_INFO_NUM_DEVICES:
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/cuda/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
size_t propSize,
void *pPropValue,
size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

static constexpr uint32_t MaxWorkItemDimensions = 3u;

Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//===----------------------------------------------------------------------===//
#pragma once

#include <ur/ur.hpp>
#include <ur_api.h>

struct ur_device_handle_t_ {
private:
Expand Down
6 changes: 4 additions & 2 deletions source/adapters/cuda/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent,
size_t propValueSize,
void *pPropValue,
size_t *pPropValueSizeRet) {
UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propValueSize, pPropValue,
pPropValueSizeRet);

switch (propName) {
case UR_EVENT_INFO_COMMAND_QUEUE:
Expand All @@ -194,7 +195,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent,
UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
ur_event_handle_t hEvent, ur_profiling_info_t propName,
size_t propValueSize, void *pPropValue, size_t *pPropValueSizeRet) {
UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propValueSize, pPropValue,
pPropValueSizeRet);

ur_queue_handle_t Queue = hEvent->getQueue();
if (Queue == nullptr || !(Queue->URFlags & UR_QUEUE_FLAG_PROFILING_ENABLE)) {
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#pragma once

#include <cuda.h>
#include <ur/ur.hpp>
#include <ur_api.h>

#include "queue.hpp"

Expand Down
1 change: 0 additions & 1 deletion source/adapters/cuda/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "memory.hpp"
#include "queue.hpp"
#include "sampler.hpp"
#include "ur/ur.hpp"
#include "ur_api.h"

ur_result_t urCalculateNumChannels(ur_image_channel_order_t order,
Expand Down
9 changes: 6 additions & 3 deletions source/adapters/cuda/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ UR_APIEXPORT ur_result_t UR_APICALL
urKernelGetGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
ur_kernel_group_info_t propName, size_t propSize,
void *pPropValue, size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

switch (propName) {
case UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE: {
Expand Down Expand Up @@ -205,7 +206,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
size_t propSize,
void *pKernelInfo,
size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pKernelInfo, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pKernelInfo,
pPropSizeRet);

switch (propName) {
case UR_KERNEL_INFO_FUNCTION_NAME:
Expand Down Expand Up @@ -237,7 +239,8 @@ UR_APIEXPORT ur_result_t UR_APICALL
urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
ur_kernel_sub_group_info_t propName, size_t propSize,
void *pPropValue, size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);
switch (propName) {
case UR_KERNEL_SUB_GROUP_INFO_MAX_SUB_GROUP_SIZE: {
// Sub-group size is equivalent to warp size
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory,
size_t *pPropSizeRet) {
UR_ASSERT(hMemory->isBuffer(), UR_RESULT_ERROR_INVALID_MEM_OBJECT);

UrReturnHelper ReturnValue(propSize, pMemInfo, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pMemInfo, pPropSizeRet);

ScopedContext Active(hMemory->getContext());

Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetInfo(
size_t Size, void *pPlatformInfo, size_t *pSizeRet) {

UR_ASSERT(hPlatform, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
UrReturnHelper ReturnValue(Size, pPlatformInfo, pSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(Size, pPlatformInfo, pSizeRet);

switch (PlatformInfoType) {
case UR_PLATFORM_INFO_NAME:
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/cuda/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
//===----------------------------------------------------------------------===//
#pragma once

#include <ur/ur.hpp>
#include <memory>
#include <ur_api.h>
#include <vector>

struct ur_platform_handle_t_ {
Expand Down
6 changes: 4 additions & 2 deletions source/adapters/cuda/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ urProgramGetBuildInfo(ur_program_handle_t hProgram, ur_device_handle_t hDevice,
void *pPropValue, size_t *pPropSizeRet) {
std::ignore = hDevice;

UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

switch (propName) {
case UR_PROGRAM_BUILD_INFO_STATUS: {
Expand All @@ -296,7 +297,8 @@ urProgramGetBuildInfo(ur_program_handle_t hProgram, ur_device_handle_t hDevice,
UR_APIEXPORT ur_result_t UR_APICALL
urProgramGetInfo(ur_program_handle_t hProgram, ur_program_info_t propName,
size_t propSize, void *pProgramInfo, size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pProgramInfo, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pProgramInfo,
pPropSizeRet);

switch (propName) {
case UR_PROGRAM_INFO_REFERENCE_COUNT:
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/cuda/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueGetInfo(ur_queue_handle_t hQueue,
size_t propValueSize,
void *pPropValue,
size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propValueSize, pPropValue,
pPropSizeRet);

switch (propName) {
case UR_QUEUE_INFO_CONTEXT:
Expand Down
4 changes: 3 additions & 1 deletion source/adapters/cuda/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
//===----------------------------------------------------------------------===//
#pragma once

#include <ur/ur.hpp>
#include <ur_api.h>

#include <algorithm>
#include <atomic>
#include <cuda.h>
#include <mutex>
#include <vector>

using ur_stream_guard_ = std::unique_lock<std::mutex>;
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/cuda/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ urSamplerCreate(ur_context_handle_t hContext, const ur_sampler_desc_t *pDesc,
UR_APIEXPORT ur_result_t UR_APICALL
urSamplerGetInfo(ur_sampler_handle_t hSampler, ur_sampler_info_t propName,
size_t propValueSize, void *pPropValue, size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propValueSize, pPropValue,
pPropSizeRet);

switch (propName) {
case UR_SAMPLER_INFO_REFERENCE_COUNT:
Expand Down
4 changes: 3 additions & 1 deletion source/adapters/cuda/sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
//
//===----------------------------------------------------------------------===//

#include <ur/ur.hpp>
#include <ur_api.h>

#include <atomic>

/// Implementation of samplers for CUDA
///
Expand Down
6 changes: 4 additions & 2 deletions source/adapters/cuda/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem,
void *pPropValue, size_t *pPropValueSizeRet) {
ur_result_t Result = UR_RESULT_SUCCESS;

UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propValueSize, pPropValue,
pPropValueSizeRet);

try {
ScopedContext Active(hContext);
Expand Down Expand Up @@ -489,7 +490,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolGetInfo(
size_t *pPropSizeRet ///< [out][optional] size in bytes returned in pool
///< property value
) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

switch (propName) {
case UR_USM_POOL_INFO_REFERENCE_COUNT: {
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/cuda/usm_p2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PPeerAccessGetInfoExp(
ur_exp_peer_info_t propName, size_t propSize, void *pPropValue,
size_t *pPropSizeRet) {

UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

int value;
CUdevice_P2PAttribute cu_attr;
Expand Down
6 changes: 0 additions & 6 deletions source/adapters/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ add_ur_adapter(${TARGET_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/sampler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/usm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/usm_p2p.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.hpp
)

if(NOT MSVC)
Expand Down Expand Up @@ -159,7 +157,3 @@ elseif("${UR_HIP_PLATFORM}" STREQUAL "NVIDIA")
else()
message(FATAL_ERROR "Unspecified UR HIP platform please set UR_HIP_PLATFORM to 'AMD' or 'NVIDIA'")
endif()

target_include_directories(${TARGET_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../"
)
3 changes: 2 additions & 1 deletion source/adapters/hip/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
size_t propSize,
void *pPropValue,
size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

switch (propName) {
case UR_ADAPTER_INFO_BACKEND:
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/hip/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
//===----------------------------------------------------------------------===//

#include <ur/ur.hpp>
#include <ur_api.h>

/// Stub implementation of command-buffers for HIP

Expand Down
3 changes: 2 additions & 1 deletion source/adapters/hip/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include <amd_comgr/amd_comgr.h>
#endif
#include <hip/hip_runtime.h>
#include <ur/ur.hpp>
#include <ur_adapter_util.hpp>
#include <ur_api.h>

// Hipify doesn't support cuArrayGetDescriptor, on AMD the hipArray can just be
// indexed, but on NVidia it is an opaque type and needs to go through
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/hip/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ UR_APIEXPORT ur_result_t UR_APICALL
urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
size_t propSize, void *pPropValue, size_t *pPropSizeRet) {

UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

switch (uint32_t{propName}) {
case UR_CONTEXT_INFO_NUM_DEVICES:
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/hip/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
size_t propSize,
void *pPropValue,
size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

static constexpr uint32_t MaxWorkItemDimensions = 3u;

Expand Down
2 changes: 1 addition & 1 deletion source/adapters/hip/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "common.hpp"

#include <ur/ur.hpp>
#include <ur_api.h>

/// UR device mapping to a hipDevice_t.
/// Includes an observer pointer to the platform,
Expand Down
6 changes: 4 additions & 2 deletions source/adapters/hip/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent,
size_t *pPropValueSizeRet) {
UR_ASSERT(!(pPropValue && propValueSize == 0), UR_RESULT_ERROR_INVALID_SIZE);

UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propValueSize, pPropValue,
pPropValueSizeRet);
switch (propName) {
case UR_EVENT_INFO_COMMAND_QUEUE:
return ReturnValue(hEvent->getQueue());
Expand Down Expand Up @@ -249,7 +250,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
return UR_RESULT_ERROR_PROFILING_INFO_NOT_AVAILABLE;
}

UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propValueSize, pPropValue,
pPropValueSizeRet);
switch (propName) {
case UR_PROFILING_INFO_COMMAND_QUEUED:
case UR_PROFILING_INFO_COMMAND_SUBMIT:
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/hip/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
//===----------------------------------------------------------------------===//

#include "ur/ur.hpp"
#include "ur_api.h"

UR_APIEXPORT ur_result_t UR_APICALL urUSMPitchedAllocExp(
[[maybe_unused]] ur_context_handle_t hContext,
Expand Down
9 changes: 6 additions & 3 deletions source/adapters/hip/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ UR_APIEXPORT ur_result_t UR_APICALL
urKernelGetGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
ur_kernel_group_info_t propName, size_t propSize,
void *pPropValue, size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);

switch (propName) {
case UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE: {
Expand Down Expand Up @@ -186,7 +187,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
size_t propSize,
void *pKernelInfo,
size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pKernelInfo, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pKernelInfo,
pPropSizeRet);

switch (propName) {
case UR_KERNEL_INFO_FUNCTION_NAME:
Expand All @@ -212,7 +214,8 @@ UR_APIEXPORT ur_result_t UR_APICALL
urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
ur_kernel_sub_group_info_t propName, size_t propSize,
void *pPropValue, size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
ur::adapter_util::ReturnHelper ReturnValue(propSize, pPropValue,
pPropSizeRet);
switch (propName) {
case UR_KERNEL_SUB_GROUP_INFO_MAX_SUB_GROUP_SIZE: {
// Sub-group size is equivalent to warp size
Expand Down
Loading

0 comments on commit ac29419

Please sign in to comment.