Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NATIVECPU] Move Native CPU adapter to UR. #1047

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ source/adapters/hip @oneapi-src/unified-runtime-hip-write
# OpenCL adapter
source/adapters/opencl @oneapi-src/unified-runtime-opencl-write

# SYCL Native CPU adapter
source/adapters/native_cpu @oneapi-src/unified-runtime-native-cpu-write

# Command-buffer experimental feature
source/adapters/**/command_buffer.* @oneapi-src/unified-runtime-command-buffer-write
scripts/core/EXP-COMMAND-BUFFER.rst @oneapi-src/unified-runtime-command-buffer-write
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ option(UR_BUILD_ADAPTER_L0 "build level 0 adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_OPENCL "build opencl adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_CUDA "build cuda adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_HIP "build hip adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_NATIVE_CPU "build native_cpu adapter from SYCL" OFF)
option(UR_BUILD_EXAMPLE_CODEGEN "Build the codegen example." OFF)
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ List of options provided by CMake:
| UR_BUILD_ADAPTER_OPENCL | Fetch and use opencl adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_CUDA | Fetch and use cuda adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_HIP | Fetch and use hip adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_NATIVE_CPU | Fetch and use native-cpu adapter from SYCL | ON/OFF | OFF |
| UR_HIP_PLATFORM | Build hip adapter for AMD or NVIDIA platform | AMD/NVIDIA | AMD |
| UR_ENABLE_COMGR | Enable comgr lib usage | AMD/NVIDIA | AMD |

Expand Down
5 changes: 5 additions & 0 deletions source/adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ endif()
if(UR_BUILD_ADAPTER_OPENCL)
add_subdirectory(opencl)
endif()

if(UR_BUILD_ADAPTER_NATIVE_CPU)
add_subdirectory(native_cpu)
endif()

4 changes: 4 additions & 0 deletions source/adapters/native_cpu/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
Language: Cpp
BasedOnStyle: LLVM
...
58 changes: 58 additions & 0 deletions source/adapters/native_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (C) 2023 Intel Corporation
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

set(NATIVE_CPU_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "Native CPU adapter directory")

set(TARGET_NAME ur_adapter_native_cpu)

add_ur_adapter(${TARGET_NAME}
SHARED
${CMAKE_CURRENT_SOURCE_DIR}/adapter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/command_buffer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/common.hpp
${CMAKE_CURRENT_SOURCE_DIR}/context.cpp
${CMAKE_CURRENT_SOURCE_DIR}/context.hpp
${CMAKE_CURRENT_SOURCE_DIR}/device.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device.hpp
${CMAKE_CURRENT_SOURCE_DIR}/enqueue.cpp
${CMAKE_CURRENT_SOURCE_DIR}/event.cpp
${CMAKE_CURRENT_SOURCE_DIR}/image.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel.hpp
${CMAKE_CURRENT_SOURCE_DIR}/memory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/memory.hpp
${CMAKE_CURRENT_SOURCE_DIR}/nativecpu_state.hpp
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform.hpp
${CMAKE_CURRENT_SOURCE_DIR}/program.cpp
${CMAKE_CURRENT_SOURCE_DIR}/program.hpp
${CMAKE_CURRENT_SOURCE_DIR}/queue.cpp
${CMAKE_CURRENT_SOURCE_DIR}/queue.hpp
${CMAKE_CURRENT_SOURCE_DIR}/sampler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ur_interface_loader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/usm_p2p.cpp
${CMAKE_CURRENT_SOURCE_DIR}/usm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.hpp
)

set_target_properties(${TARGET_NAME} PROPERTIES
VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
)

find_package(Threads REQUIRED)

target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::unified_malloc_framework
Threads::Threads
)

target_include_directories(${TARGET_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../"
)
73 changes: 73 additions & 0 deletions source/adapters/native_cpu/adapter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//===--------- adapter.cpp - Native CPU Adapter ---------------------------===//
//
// Copyright (C) 2023 Intel Corporation
//
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "common.hpp"
#include "ur_api.h"

struct ur_adapter_handle_t_ {
std::atomic<uint32_t> RefCount = 0;
} Adapter;

UR_APIEXPORT ur_result_t UR_APICALL urInit(ur_device_init_flags_t,
ur_loader_config_handle_t) {
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urTearDown(void *) {
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterGet(
uint32_t, ur_adapter_handle_t *phAdapters, uint32_t *pNumAdapters) {
if (phAdapters) {
Adapter.RefCount++;
*phAdapters = &Adapter;
}
if (pNumAdapters) {
*pNumAdapters = 1;
}
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterRelease(ur_adapter_handle_t) {
Adapter.RefCount--;
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) {
Adapter.RefCount++;
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
ur_adapter_handle_t, const char **ppMessage, int32_t *pError) {
*ppMessage = ErrorMessage;
*pError = ErrorMessageCode;
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
ur_adapter_info_t propName,
size_t propSize,
void *pPropValue,
size_t *pPropSizeRet) {
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);

switch (propName) {
case UR_ADAPTER_INFO_BACKEND:
return ReturnValue(UR_ADAPTER_BACKEND_NATIVE_CPU);
case UR_ADAPTER_INFO_REFERENCE_COUNT:
return ReturnValue(Adapter.RefCount.load());
default:
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}

return UR_RESULT_SUCCESS;
}
133 changes: 133 additions & 0 deletions source/adapters/native_cpu/command_buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//===--------- command_buffer.cpp - Native CPU Adapter --------------------===//
//
// Copyright (C) 2023 Intel Corporation
//
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "common.hpp"

/// Stub implementations of UR experimental feature command-buffers
/// Taken almost unchanged from another adapter. Perhaps going forward
/// these stubs could be defined in core UR as the default which would
/// reduce code duplication. Adapters could then "override" these defaults.

UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
ur_context_handle_t, ur_device_handle_t,
const ur_exp_command_buffer_desc_t *, ur_exp_command_buffer_handle_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT ur_result_t UR_APICALL
urCommandBufferRetainExp(ur_exp_command_buffer_handle_t) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT ur_result_t UR_APICALL
urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT ur_result_t UR_APICALL
urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
ur_exp_command_buffer_handle_t, ur_kernel_handle_t, uint32_t,
const size_t *, const size_t *, const size_t *, uint32_t,
const ur_exp_command_buffer_sync_point_t *,
ur_exp_command_buffer_sync_point_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemcpyUSMExp(
ur_exp_command_buffer_handle_t, void *, const void *, size_t, uint32_t,
const ur_exp_command_buffer_sync_point_t *,
ur_exp_command_buffer_sync_point_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMembufferCopyExp(
ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_mem_handle_t, size_t,
size_t, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *,
ur_exp_command_buffer_sync_point_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMembufferCopyRectExp(
ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_mem_handle_t,
ur_rect_offset_t, ur_rect_offset_t, ur_rect_region_t, size_t, size_t,
size_t, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *,
ur_exp_command_buffer_sync_point_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT
ur_result_t UR_APICALL urCommandBufferAppendMembufferWriteExp(
ur_exp_command_buffer_handle_t, ur_mem_handle_t, size_t, size_t,
const void *, uint32_t, const ur_exp_command_buffer_sync_point_t *,
ur_exp_command_buffer_sync_point_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT
ur_result_t UR_APICALL urCommandBufferAppendMembufferReadExp(
ur_exp_command_buffer_handle_t, ur_mem_handle_t, size_t, size_t, void *,
uint32_t, const ur_exp_command_buffer_sync_point_t *,
ur_exp_command_buffer_sync_point_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT
ur_result_t UR_APICALL urCommandBufferAppendMembufferWriteRectExp(
ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_rect_offset_t,
ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, void *,
uint32_t, const ur_exp_command_buffer_sync_point_t *,
ur_exp_command_buffer_sync_point_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT
ur_result_t UR_APICALL urCommandBufferAppendMembufferReadRectExp(
ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_rect_offset_t,
ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, void *,
uint32_t, const ur_exp_command_buffer_sync_point_t *,
ur_exp_command_buffer_sync_point_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(
ur_exp_command_buffer_handle_t, ur_queue_handle_t, uint32_t,
const ur_event_handle_t *, ur_event_handle_t *) {
detail::ur::die("Experimental Command-buffer feature is not "
"implemented for the NativeCPU adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
34 changes: 34 additions & 0 deletions source/adapters/native_cpu/common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===--------- common.cpp - Native CPU Adapter ---------------------------===//
//
// Copyright (C) 2023 Intel Corporation
//
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "common.hpp"

// Global variables for UR_RESULT_ADAPTER_SPECIFIC_ERROR
// See urGetLastResult
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
thread_local char ErrorMessage[MaxMessageSize];

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *pMessage,
ur_result_t ErrorCode) {
assert(strlen(pMessage) <= MaxMessageSize);
strcpy(ErrorMessage, pMessage);
ErrorMessageCode = ErrorCode;
}

ur_result_t urGetLastResult(ur_platform_handle_t, const char **ppMessage) {
*ppMessage = &ErrorMessage[0];
return ErrorMessageCode;
}

void detail::ur::die(const char *pMessage) {
std::cerr << "ur_die: " << pMessage << '\n';
std::terminate();
}
Loading
Loading