Skip to content

Commit 659d3f4

Browse files
authored
Merge pull request #1059 from martygrant/martin/moveNativeCPUAdapterToUR
[NATIVECPU] Move Native CPU adapter to UR.
2 parents 192e940 + f94550b commit 659d3f4

33 files changed

+3493
-1
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ source/adapters/hip @oneapi-src/unified-runtime-hip-write
1010
# OpenCL adapter
1111
source/adapters/opencl @oneapi-src/unified-runtime-opencl-write
1212

13+
# Native CPU adapter
14+
source/adapters/native_cpu @oneapi-src/unified-runtime-native-cpu-write
15+
1316
# Command-buffer experimental feature
1417
source/adapters/**/command_buffer.* @oneapi-src/unified-runtime-command-buffer-write
1518
scripts/core/EXP-COMMAND-BUFFER.rst @oneapi-src/unified-runtime-command-buffer-write

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ option(UR_BUILD_ADAPTER_L0 "build level 0 adapter from SYCL" OFF)
3939
option(UR_BUILD_ADAPTER_OPENCL "build opencl adapter from SYCL" OFF)
4040
option(UR_BUILD_ADAPTER_CUDA "build cuda adapter from SYCL" OFF)
4141
option(UR_BUILD_ADAPTER_HIP "build hip adapter from SYCL" OFF)
42+
option(UR_BUILD_ADAPTER_NATIVE_CPU "build native_cpu adapter from SYCL" OFF)
4243
option(UR_BUILD_EXAMPLE_CODEGEN "Build the codegen example." OFF)
4344
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
4445
set(UR_DPCXX "" CACHE FILEPATH "Path of the DPC++ compiler executable")

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ List of options provided by CMake:
131131
| UR_BUILD_ADAPTER_OPENCL | Fetch and use opencl adapter from SYCL | ON/OFF | OFF |
132132
| UR_BUILD_ADAPTER_CUDA | Fetch and use cuda adapter from SYCL | ON/OFF | OFF |
133133
| UR_BUILD_ADAPTER_HIP | Fetch and use hip adapter from SYCL | ON/OFF | OFF |
134+
| UR_BUILD_ADAPTER_NATIVE_CPU | Fetch and use native-cpu adapter from SYCL | ON/OFF | OFF |
134135
| UR_HIP_PLATFORM | Build hip adapter for AMD or NVIDIA platform | AMD/NVIDIA | AMD |
135136
| UR_ENABLE_COMGR | Enable comgr lib usage | AMD/NVIDIA | AMD |
136137
| UR_DPCXX | Path of the DPC++ compiler executable to build CTS device binaries | File path | `""` |

source/adapters/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ endif()
4747
if(UR_BUILD_ADAPTER_OPENCL)
4848
add_subdirectory(opencl)
4949
endif()
50+
if(UR_BUILD_ADAPTER_NATIVE_CPU)
51+
add_subdirectory(native_cpu)
52+
endif()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: LLVM
4+
...
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (C) 2023 Intel Corporation
2+
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See LICENSE.TXT
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
set(NATIVE_CPU_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "Native CPU adapter directory")
7+
8+
set(TARGET_NAME ur_adapter_native_cpu)
9+
10+
add_ur_adapter(${TARGET_NAME}
11+
SHARED
12+
${CMAKE_CURRENT_SOURCE_DIR}/adapter.cpp
13+
${CMAKE_CURRENT_SOURCE_DIR}/command_buffer.cpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/common.cpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/common.hpp
16+
${CMAKE_CURRENT_SOURCE_DIR}/context.cpp
17+
${CMAKE_CURRENT_SOURCE_DIR}/context.hpp
18+
${CMAKE_CURRENT_SOURCE_DIR}/device.cpp
19+
${CMAKE_CURRENT_SOURCE_DIR}/device.hpp
20+
${CMAKE_CURRENT_SOURCE_DIR}/enqueue.cpp
21+
${CMAKE_CURRENT_SOURCE_DIR}/event.cpp
22+
${CMAKE_CURRENT_SOURCE_DIR}/image.cpp
23+
${CMAKE_CURRENT_SOURCE_DIR}/kernel.cpp
24+
${CMAKE_CURRENT_SOURCE_DIR}/kernel.hpp
25+
${CMAKE_CURRENT_SOURCE_DIR}/memory.cpp
26+
${CMAKE_CURRENT_SOURCE_DIR}/memory.hpp
27+
${CMAKE_CURRENT_SOURCE_DIR}/nativecpu_state.hpp
28+
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp
29+
${CMAKE_CURRENT_SOURCE_DIR}/platform.hpp
30+
${CMAKE_CURRENT_SOURCE_DIR}/program.cpp
31+
${CMAKE_CURRENT_SOURCE_DIR}/program.hpp
32+
${CMAKE_CURRENT_SOURCE_DIR}/queue.cpp
33+
${CMAKE_CURRENT_SOURCE_DIR}/queue.hpp
34+
${CMAKE_CURRENT_SOURCE_DIR}/sampler.cpp
35+
${CMAKE_CURRENT_SOURCE_DIR}/ur_interface_loader.cpp
36+
${CMAKE_CURRENT_SOURCE_DIR}/usm_p2p.cpp
37+
${CMAKE_CURRENT_SOURCE_DIR}/usm.cpp
38+
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.cpp
39+
${CMAKE_CURRENT_SOURCE_DIR}/../../ur/ur.hpp
40+
)
41+
42+
set_target_properties(${TARGET_NAME} PROPERTIES
43+
VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
44+
SOVERSION "${PROJECT_VERSION_MAJOR}"
45+
)
46+
47+
find_package(Threads REQUIRED)
48+
49+
target_link_libraries(${TARGET_NAME} PRIVATE
50+
${PROJECT_NAME}::headers
51+
${PROJECT_NAME}::common
52+
${PROJECT_NAME}::unified_malloc_framework
53+
Threads::Threads
54+
)
55+
56+
target_include_directories(${TARGET_NAME} PRIVATE
57+
"${CMAKE_CURRENT_SOURCE_DIR}/../../"
58+
)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//===---------------- adapter.cpp - Native CPU Adapter --------------------===//
2+
//
3+
// Copyright (C) 2023 Intel Corporation
4+
//
5+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
6+
// Exceptions. See LICENSE.TXT
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
#include "common.hpp"
12+
#include "ur_api.h"
13+
14+
struct ur_adapter_handle_t_ {
15+
std::atomic<uint32_t> RefCount = 0;
16+
} Adapter;
17+
18+
UR_APIEXPORT ur_result_t UR_APICALL urInit(ur_device_init_flags_t,
19+
ur_loader_config_handle_t) {
20+
return UR_RESULT_SUCCESS;
21+
}
22+
23+
UR_APIEXPORT ur_result_t UR_APICALL urTearDown(void *) {
24+
return UR_RESULT_SUCCESS;
25+
}
26+
27+
UR_APIEXPORT ur_result_t UR_APICALL urAdapterGet(
28+
uint32_t, ur_adapter_handle_t *phAdapters, uint32_t *pNumAdapters) {
29+
if (phAdapters) {
30+
Adapter.RefCount++;
31+
*phAdapters = &Adapter;
32+
}
33+
if (pNumAdapters) {
34+
*pNumAdapters = 1;
35+
}
36+
return UR_RESULT_SUCCESS;
37+
}
38+
39+
UR_APIEXPORT ur_result_t UR_APICALL urAdapterRelease(ur_adapter_handle_t) {
40+
Adapter.RefCount--;
41+
return UR_RESULT_SUCCESS;
42+
}
43+
44+
UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) {
45+
Adapter.RefCount++;
46+
return UR_RESULT_SUCCESS;
47+
}
48+
49+
UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
50+
ur_adapter_handle_t, const char **ppMessage, int32_t *pError) {
51+
*ppMessage = ErrorMessage;
52+
*pError = ErrorMessageCode;
53+
return UR_RESULT_SUCCESS;
54+
}
55+
56+
UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
57+
ur_adapter_info_t propName,
58+
size_t propSize,
59+
void *pPropValue,
60+
size_t *pPropSizeRet) {
61+
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
62+
63+
switch (propName) {
64+
case UR_ADAPTER_INFO_BACKEND:
65+
return ReturnValue(UR_ADAPTER_BACKEND_NATIVE_CPU);
66+
case UR_ADAPTER_INFO_REFERENCE_COUNT:
67+
return ReturnValue(Adapter.RefCount.load());
68+
default:
69+
return UR_RESULT_ERROR_INVALID_ENUMERATION;
70+
}
71+
72+
return UR_RESULT_SUCCESS;
73+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
//===--------- command_buffer.cpp - NativeCPU Adapter ---------------------===//
2+
//
3+
// Copyright (C) 2023 Intel Corporation
4+
//
5+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
6+
// Exceptions. See LICENSE.TXT
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
#include "common.hpp"
12+
13+
/// Stub implementations of UR experimental feature command-buffers
14+
/// Taken almost unchanged from another adapter. Perhaps going forward
15+
/// these stubs could be defined in core UR as the default which would
16+
/// reduce code duplication. Adapters could then "override" these defaults.
17+
/// Issue raised for this comment in
18+
/// https://github.com/oneapi-src/unified-runtime/issues/1064
19+
20+
UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
21+
ur_context_handle_t, ur_device_handle_t,
22+
const ur_exp_command_buffer_desc_t *, ur_exp_command_buffer_handle_t *) {
23+
detail::ur::die("Experimental Command-buffer feature is not "
24+
"implemented for the NativeCPU adapter.");
25+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
26+
}
27+
28+
UR_APIEXPORT ur_result_t UR_APICALL
29+
urCommandBufferRetainExp(ur_exp_command_buffer_handle_t) {
30+
detail::ur::die("Experimental Command-buffer feature is not "
31+
"implemented for the NativeCPU adapter.");
32+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
33+
}
34+
35+
UR_APIEXPORT ur_result_t UR_APICALL
36+
urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t) {
37+
detail::ur::die("Experimental Command-buffer feature is not "
38+
"implemented for the NativeCPU adapter.");
39+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
40+
}
41+
42+
UR_APIEXPORT ur_result_t UR_APICALL
43+
urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t) {
44+
detail::ur::die("Experimental Command-buffer feature is not "
45+
"implemented for the NativeCPU adapter.");
46+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
47+
}
48+
49+
UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
50+
ur_exp_command_buffer_handle_t, ur_kernel_handle_t, uint32_t,
51+
const size_t *, const size_t *, const size_t *, uint32_t,
52+
const ur_exp_command_buffer_sync_point_t *,
53+
ur_exp_command_buffer_sync_point_t *) {
54+
detail::ur::die("Experimental Command-buffer feature is not "
55+
"implemented for the NativeCPU adapter.");
56+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
57+
}
58+
59+
UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemcpyUSMExp(
60+
ur_exp_command_buffer_handle_t, void *, const void *, size_t, uint32_t,
61+
const ur_exp_command_buffer_sync_point_t *,
62+
ur_exp_command_buffer_sync_point_t *) {
63+
detail::ur::die("Experimental Command-buffer feature is not "
64+
"implemented for the NativeCPU adapter.");
65+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
66+
}
67+
68+
UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMembufferCopyExp(
69+
ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_mem_handle_t, size_t,
70+
size_t, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *,
71+
ur_exp_command_buffer_sync_point_t *) {
72+
detail::ur::die("Experimental Command-buffer feature is not "
73+
"implemented for the NativeCPU adapter.");
74+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
75+
}
76+
77+
UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMembufferCopyRectExp(
78+
ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_mem_handle_t,
79+
ur_rect_offset_t, ur_rect_offset_t, ur_rect_region_t, size_t, size_t,
80+
size_t, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *,
81+
ur_exp_command_buffer_sync_point_t *) {
82+
detail::ur::die("Experimental Command-buffer feature is not "
83+
"implemented for the NativeCPU adapter.");
84+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
85+
}
86+
87+
UR_APIEXPORT
88+
ur_result_t UR_APICALL urCommandBufferAppendMembufferWriteExp(
89+
ur_exp_command_buffer_handle_t, ur_mem_handle_t, size_t, size_t,
90+
const void *, uint32_t, const ur_exp_command_buffer_sync_point_t *,
91+
ur_exp_command_buffer_sync_point_t *) {
92+
detail::ur::die("Experimental Command-buffer feature is not "
93+
"implemented for the NativeCPU adapter.");
94+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
95+
}
96+
97+
UR_APIEXPORT
98+
ur_result_t UR_APICALL urCommandBufferAppendMembufferReadExp(
99+
ur_exp_command_buffer_handle_t, ur_mem_handle_t, size_t, size_t, void *,
100+
uint32_t, const ur_exp_command_buffer_sync_point_t *,
101+
ur_exp_command_buffer_sync_point_t *) {
102+
detail::ur::die("Experimental Command-buffer feature is not "
103+
"implemented for the NativeCPU adapter.");
104+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
105+
}
106+
107+
UR_APIEXPORT
108+
ur_result_t UR_APICALL urCommandBufferAppendMembufferWriteRectExp(
109+
ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_rect_offset_t,
110+
ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, void *,
111+
uint32_t, const ur_exp_command_buffer_sync_point_t *,
112+
ur_exp_command_buffer_sync_point_t *) {
113+
detail::ur::die("Experimental Command-buffer feature is not "
114+
"implemented for the NativeCPU adapter.");
115+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
116+
}
117+
118+
UR_APIEXPORT
119+
ur_result_t UR_APICALL urCommandBufferAppendMembufferReadRectExp(
120+
ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_rect_offset_t,
121+
ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, void *,
122+
uint32_t, const ur_exp_command_buffer_sync_point_t *,
123+
ur_exp_command_buffer_sync_point_t *) {
124+
detail::ur::die("Experimental Command-buffer feature is not "
125+
"implemented for the NativeCPU adapter.");
126+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
127+
}
128+
129+
UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(
130+
ur_exp_command_buffer_handle_t, ur_queue_handle_t, uint32_t,
131+
const ur_event_handle_t *, ur_event_handle_t *) {
132+
detail::ur::die("Experimental Command-buffer feature is not "
133+
"implemented for the NativeCPU adapter.");
134+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
135+
}

source/adapters/native_cpu/common.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===---------------- common.cpp - Native CPU Adapter ---------------------===//
2+
//
3+
// Copyright (C) 2023 Intel Corporation
4+
//
5+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
6+
// Exceptions. See LICENSE.TXT
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
#include "common.hpp"
12+
13+
// Global variables for UR_RESULT_ADAPTER_SPECIFIC_ERROR
14+
// See urGetLastResult
15+
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
16+
thread_local char ErrorMessage[MaxMessageSize];
17+
18+
// Utility function for setting a message and warning
19+
[[maybe_unused]] void setErrorMessage(const char *pMessage,
20+
ur_result_t ErrorCode) {
21+
assert(strlen(pMessage) <= MaxMessageSize);
22+
strcpy(ErrorMessage, pMessage);
23+
ErrorMessageCode = ErrorCode;
24+
}
25+
26+
ur_result_t urGetLastResult(ur_platform_handle_t, const char **ppMessage) {
27+
*ppMessage = &ErrorMessage[0];
28+
return ErrorMessageCode;
29+
}
30+
31+
void detail::ur::die(const char *pMessage) {
32+
std::cerr << "ur_die: " << pMessage << '\n';
33+
std::terminate();
34+
}

0 commit comments

Comments
 (0)