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 Dec 12, 2023
1 parent 69a56ea commit f17e787
Show file tree
Hide file tree
Showing 95 changed files with 581 additions and 614 deletions.
6 changes: 0 additions & 6 deletions source/adapters/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,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 @@ -80,7 +78,3 @@ target_link_libraries(${TARGET_NAME} PRIVATE
Threads::Threads
cudadrv
)

target_include_directories(${TARGET_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../"
)
2 changes: 1 addition & 1 deletion source/adapters/cuda/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ 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::ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);

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

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

#include "context.hpp"
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_util.hpp>

ur_result_t mapErrorUR(CUresult Result);

Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ 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::ReturnHelper ReturnValue(propSize, pContextInfo, pPropSizeRet);

switch (static_cast<uint32_t>(ContextInfoType)) {
case UR_CONTEXT_INFO_NUM_DEVICES:
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ 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::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
4 changes: 2 additions & 2 deletions source/adapters/cuda/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ 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::ReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);

switch (propName) {
case UR_EVENT_INFO_COMMAND_QUEUE:
Expand All @@ -194,7 +194,7 @@ 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::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
6 changes: 3 additions & 3 deletions source/adapters/cuda/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ 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::ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);

switch (propName) {
case UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE: {
Expand Down Expand Up @@ -205,7 +205,7 @@ 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::ReturnHelper ReturnValue(propSize, pKernelInfo, pPropSizeRet);

switch (propName) {
case UR_KERNEL_INFO_FUNCTION_NAME:
Expand Down Expand Up @@ -237,7 +237,7 @@ 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::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::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::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
4 changes: 2 additions & 2 deletions source/adapters/cuda/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ 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::ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);

switch (propName) {
case UR_PROGRAM_BUILD_INFO_STATUS: {
Expand All @@ -359,7 +359,7 @@ 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::ReturnHelper ReturnValue(propSize, pProgramInfo, pPropSizeRet);

switch (propName) {
case UR_PROGRAM_INFO_REFERENCE_COUNT:
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ 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::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
2 changes: 1 addition & 1 deletion source/adapters/cuda/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ 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::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
4 changes: 2 additions & 2 deletions source/adapters/cuda/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ 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::ReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);

try {
ScopedContext Active(hContext);
Expand Down Expand Up @@ -489,7 +489,7 @@ 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::ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);

switch (propName) {
case UR_USM_POOL_INFO_REFERENCE_COUNT: {
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/usm_p2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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::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 @@ -71,8 +71,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 @@ -157,7 +155,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}/../../"
)
2 changes: 1 addition & 1 deletion source/adapters/hip/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ 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::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_api.h>
#include <ur_util.hpp>

// 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
2 changes: 1 addition & 1 deletion source/adapters/hip/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ 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::ReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);

switch (uint32_t{propName}) {
case UR_CONTEXT_INFO_NUM_DEVICES:
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/hip/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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::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
12 changes: 6 additions & 6 deletions source/adapters/hip/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferRead(

std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};

ur_lock MemoryMigrationLock{hBuffer->MemoryMigrationMutex};
ur::Lock MemoryMigrationLock{hBuffer->MemoryMigrationMutex};
auto Device = hQueue->getDevice();
hipStream_t HIPStream = hQueue->getNextTransferStream();

Expand Down Expand Up @@ -215,7 +215,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(

std::vector<ur_event_handle_t> DepEvents(
phEventWaitList, phEventWaitList + numEventsInWaitList);
std::vector<std::pair<ur_mem_handle_t, ur_lock>> MemMigrationLocks;
std::vector<std::pair<ur_mem_handle_t, ur::Lock>> MemMigrationLocks;

// phEventWaitList only contains events that are handed to UR by the SYCL
// runtime. However since UR handles memory dependencies within a context
Expand All @@ -238,8 +238,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
[MemArg](auto &Lock) {
return Lock.first == MemArg.Mem;
}) == MemMigrationLocks.end())
MemMigrationLocks.emplace_back(
std::pair{MemArg.Mem, ur_lock{MemArg.Mem->MemoryMigrationMutex}});
MemMigrationLocks.emplace_back(std::pair{
MemArg.Mem, ur::Lock{MemArg.Mem->MemoryMigrationMutex}});
}
}
}
Expand Down Expand Up @@ -593,7 +593,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferReadRect(
std::unique_ptr<ur_event_handle_t_> RetImplEvent{nullptr};

ur_result_t Result = UR_RESULT_SUCCESS;
ur_lock MemoryMigrationLock(hBuffer->MemoryMigrationMutex);
ur::Lock MemoryMigrationLock(hBuffer->MemoryMigrationMutex);
auto Device = hQueue->getDevice();
hipStream_t HIPStream = hQueue->getNextTransferStream();

Expand Down Expand Up @@ -989,7 +989,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead(

ur_result_t Result = UR_RESULT_SUCCESS;

ur_lock MemoryMigrationLock{hImage->MemoryMigrationMutex};
ur::Lock MemoryMigrationLock{hImage->MemoryMigrationMutex};
auto Device = hQueue->getDevice();
hipStream_t HIPStream = hQueue->getNextTransferStream();

Expand Down
4 changes: 2 additions & 2 deletions source/adapters/hip/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ 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::ReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
switch (propName) {
case UR_EVENT_INFO_COMMAND_QUEUE:
return ReturnValue(hEvent->getQueue());
Expand Down Expand Up @@ -249,7 +249,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
return UR_RESULT_ERROR_PROFILING_INFO_NOT_AVAILABLE;
}

UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
ur::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
Loading

0 comments on commit f17e787

Please sign in to comment.