Skip to content

Commit 4a9468f

Browse files
committed
Merge branch 'merge-some-main-changes-into-adapters-second-patch' into merge-some-main-changes-into-adapters-third-patch
2 parents b22a0ae + dad6534 commit 4a9468f

37 files changed

+3531
-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
@@ -40,6 +40,7 @@ option(UR_BUILD_ADAPTER_L0 "build level 0 adapter from SYCL" OFF)
4040
option(UR_BUILD_ADAPTER_OPENCL "build opencl adapter from SYCL" OFF)
4141
option(UR_BUILD_ADAPTER_CUDA "build cuda adapter from SYCL" OFF)
4242
option(UR_BUILD_ADAPTER_HIP "build hip adapter from SYCL" OFF)
43+
option(UR_BUILD_ADAPTER_NATIVE_CPU "build native_cpu adapter from SYCL" OFF)
4344
option(UR_BUILD_EXAMPLE_CODEGEN "Build the codegen example." OFF)
4445
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
4546
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
@@ -134,6 +134,7 @@ List of options provided by CMake:
134134
| UR_BUILD_ADAPTER_OPENCL | Fetch and use opencl adapter from SYCL | ON/OFF | OFF |
135135
| UR_BUILD_ADAPTER_CUDA | Fetch and use cuda adapter from SYCL | ON/OFF | OFF |
136136
| UR_BUILD_ADAPTER_HIP | Fetch and use hip adapter from SYCL | ON/OFF | OFF |
137+
| UR_BUILD_ADAPTER_NATIVE_CPU | Fetch and use native-cpu adapter from SYCL | ON/OFF | OFF |
137138
| UR_HIP_PLATFORM | Build hip adapter for AMD or NVIDIA platform | AMD/NVIDIA | AMD |
138139
| UR_ENABLE_COMGR | Enable comgr lib usage | AMD/NVIDIA | AMD |
139140
| 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()

source/adapters/cuda/ur_interface_loader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueExpProcAddrTable(
395395
return result;
396396
}
397397

398+
pDdiTable->pfnCooperativeKernelLaunchExp = nullptr;
399+
398400
return UR_RESULT_SUCCESS;
399401
}
400402

@@ -405,6 +407,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetKernelExpProcAddrTable(
405407
return result;
406408
}
407409

410+
pDdiTable->pfnSuggestMaxCooperativeGroupCountExp = nullptr;
411+
408412
return UR_RESULT_SUCCESS;
409413
}
410414

source/adapters/hip/ur_interface_loader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueExpProcAddrTable(
349349
return result;
350350
}
351351

352+
pDdiTable->pfnCooperativeKernelLaunchExp = nullptr;
353+
352354
return UR_RESULT_SUCCESS;
353355
}
354356

@@ -359,6 +361,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetKernelExpProcAddrTable(
359361
return result;
360362
}
361363

364+
pDdiTable->pfnSuggestMaxCooperativeGroupCountExp = nullptr;
365+
362366
return UR_RESULT_SUCCESS;
363367
}
364368

source/adapters/level_zero/ur_interface_loader.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <ur_api.h>
1212
#include <ur_ddi.h>
1313

14+
namespace {
15+
1416
ur_result_t validateProcInputs(ur_api_version_t version, void *pDdiTable) {
1517
if (nullptr == pDdiTable) {
1618
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
@@ -22,6 +24,11 @@ ur_result_t validateProcInputs(ur_api_version_t version, void *pDdiTable) {
2224
}
2325
return UR_RESULT_SUCCESS;
2426
}
27+
} // namespace
28+
29+
#if defined(__cplusplus)
30+
extern "C" {
31+
#endif
2532

2633
UR_DLLEXPORT ur_result_t UR_APICALL urGetGlobalProcAddrTable(
2734
ur_api_version_t version, ///< [in] API version requested
@@ -435,6 +442,8 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueExpProcAddrTable(
435442
return result;
436443
}
437444

445+
pDdiTable->pfnCooperativeKernelLaunchExp = nullptr;
446+
438447
return UR_RESULT_SUCCESS;
439448
}
440449

@@ -445,5 +454,10 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetKernelExpProcAddrTable(
445454
return result;
446455
}
447456

457+
pDdiTable->pfnSuggestMaxCooperativeGroupCountExp = nullptr;
458+
448459
return UR_RESULT_SUCCESS;
449460
}
461+
#if defined(__cplusplus)
462+
} // extern "C"
463+
#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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 urAdapterGet(
19+
uint32_t, ur_adapter_handle_t *phAdapters, uint32_t *pNumAdapters) {
20+
if (phAdapters) {
21+
Adapter.RefCount++;
22+
*phAdapters = &Adapter;
23+
}
24+
if (pNumAdapters) {
25+
*pNumAdapters = 1;
26+
}
27+
return UR_RESULT_SUCCESS;
28+
}
29+
30+
UR_APIEXPORT ur_result_t UR_APICALL urAdapterRelease(ur_adapter_handle_t) {
31+
Adapter.RefCount--;
32+
return UR_RESULT_SUCCESS;
33+
}
34+
35+
UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) {
36+
Adapter.RefCount++;
37+
return UR_RESULT_SUCCESS;
38+
}
39+
40+
UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
41+
ur_adapter_handle_t, const char **ppMessage, int32_t *pError) {
42+
*ppMessage = ErrorMessage;
43+
*pError = ErrorMessageCode;
44+
return UR_RESULT_SUCCESS;
45+
}
46+
47+
UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
48+
ur_adapter_info_t propName,
49+
size_t propSize,
50+
void *pPropValue,
51+
size_t *pPropSizeRet) {
52+
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
53+
54+
switch (propName) {
55+
case UR_ADAPTER_INFO_BACKEND:
56+
return ReturnValue(UR_ADAPTER_BACKEND_NATIVE_CPU);
57+
case UR_ADAPTER_INFO_REFERENCE_COUNT:
58+
return ReturnValue(Adapter.RefCount.load());
59+
default:
60+
return UR_RESULT_ERROR_INVALID_ENUMERATION;
61+
}
62+
63+
return UR_RESULT_SUCCESS;
64+
}

0 commit comments

Comments
 (0)