Skip to content

Commit 58b72b8

Browse files
Alcpzmartygrant
authored andcommitted
[SYCL][NATIVECPU] Refactor from PI plugin to UR adapter (#10523)
This PR refactors the current SYCL Native CPU Implementation as a Unified Runtime adapter. No new functionalities are added. Contents of this PR: - Native CPU implementation divided in multiple source files at `sycl/plugins/unified_runtime/ur/adapters/native_cpu` - Native CPU PI plugin is now implemented through the `pi2ur.hpp` interface - _pi_* classes have now an equivalent ur_* class - `UR_PLATFORM_BACKEND_NATIVE_CPU` value added to `ur2piPlatformInfoValue`
1 parent d70bae4 commit 58b72b8

23 files changed

+2557
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===---------------- common.cpp - Native CPU Adapter ---------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "common.hpp"
10+
11+
// Global variables for UR_RESULT_ADAPTER_SPECIFIC_ERROR
12+
// See urGetLastResult
13+
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
14+
thread_local char ErrorMessage[MaxMessageSize];
15+
16+
// Utility function for setting a message and warning
17+
[[maybe_unused]] void setErrorMessage(const char *pMessage,
18+
ur_result_t ErrorCode) {
19+
assert(strlen(pMessage) <= MaxMessageSize);
20+
strcpy(ErrorMessage, pMessage);
21+
ErrorMessageCode = ErrorCode;
22+
}
23+
24+
ur_result_t urGetLastResult(ur_platform_handle_t, const char **ppMessage) {
25+
*ppMessage = &ErrorMessage[0];
26+
return ErrorMessageCode;
27+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===----------- common.cpp - Native CPU Adapter ---------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include "ur/ur.hpp"
12+
13+
constexpr size_t MaxMessageSize = 256;
14+
15+
extern thread_local ur_result_t ErrorMessageCode;
16+
extern thread_local char ErrorMessage[MaxMessageSize];
17+
18+
#define DIE_NO_IMPLEMENTATION \
19+
if (PrintTrace) { \
20+
std::cerr << "Not Implemented : " << __FUNCTION__ \
21+
<< " - File : " << __FILE__; \
22+
std::cerr << " / Line : " << __LINE__ << std::endl; \
23+
} \
24+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
25+
26+
#define CONTINUE_NO_IMPLEMENTATION \
27+
if (PrintTrace) { \
28+
std::cerr << "Warning : Not Implemented : " << __FUNCTION__ \
29+
<< " - File : " << __FILE__; \
30+
std::cerr << " / Line : " << __LINE__ << std::endl; \
31+
} \
32+
return UR_RESULT_SUCCESS;
33+
34+
#define CASE_UR_UNSUPPORTED(not_supported) \
35+
case not_supported: \
36+
if (PrintTrace) { \
37+
std::cerr << std::endl \
38+
<< "Unsupported UR case : " << #not_supported << " in " \
39+
<< __FUNCTION__ << ":" << __LINE__ << "(" << __FILE__ << ")" \
40+
<< std::endl; \
41+
} \
42+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//===--------- context.cpp - Native CPU Adapter ---------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <memory>
10+
#include <tuple>
11+
12+
#include "ur/ur.hpp"
13+
#include "ur_api.h"
14+
15+
#include "common.hpp"
16+
#include "context.hpp"
17+
18+
UR_APIEXPORT ur_result_t UR_APICALL
19+
urContextCreate(uint32_t DeviceCount, const ur_device_handle_t *phDevices,
20+
const ur_context_properties_t *pProperties,
21+
ur_context_handle_t *phContext) {
22+
std::ignore = pProperties;
23+
UR_ASSERT(phDevices, UR_RESULT_ERROR_INVALID_NULL_POINTER);
24+
UR_ASSERT(phContext, UR_RESULT_ERROR_INVALID_NULL_POINTER);
25+
26+
assert(DeviceCount == 1);
27+
28+
// TODO: Proper error checking.
29+
auto ctx = new ur_context_handle_t_(*phDevices);
30+
*phContext = ctx;
31+
return UR_RESULT_SUCCESS;
32+
}
33+
34+
UR_APIEXPORT ur_result_t UR_APICALL
35+
urContextRetain(ur_context_handle_t hContext) {
36+
std::ignore = hContext;
37+
DIE_NO_IMPLEMENTATION
38+
}
39+
40+
UR_APIEXPORT ur_result_t UR_APICALL
41+
urContextRelease(ur_context_handle_t hContext) {
42+
delete hContext;
43+
return UR_RESULT_SUCCESS;
44+
}
45+
46+
UR_APIEXPORT ur_result_t UR_APICALL
47+
urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
48+
size_t propSize, void *pPropValue, size_t *pPropSizeRet) {
49+
50+
UR_ASSERT(hContext, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
51+
52+
UrReturnHelper returnValue(propSize, pPropValue, pPropSizeRet);
53+
54+
switch (propName) {
55+
case UR_CONTEXT_INFO_NUM_DEVICES:
56+
return returnValue(1);
57+
case UR_CONTEXT_INFO_DEVICES:
58+
return returnValue(hContext->_device);
59+
case UR_CONTEXT_INFO_REFERENCE_COUNT:
60+
return returnValue(nullptr);
61+
case UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT:
62+
return returnValue(true);
63+
case UR_CONTEXT_INFO_USM_FILL2D_SUPPORT:
64+
// case UR_CONTEXT_INFO_USM_MEMSET2D_SUPPORT:
65+
// 2D USM operations currently not supported.
66+
return returnValue(false);
67+
case UR_CONTEXT_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES:
68+
case UR_CONTEXT_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES:
69+
case UR_CONTEXT_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES:
70+
case UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES: {
71+
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
72+
}
73+
default:
74+
return UR_RESULT_ERROR_INVALID_ENUMERATION;
75+
}
76+
}
77+
78+
UR_APIEXPORT ur_result_t UR_APICALL urContextGetNativeHandle(
79+
ur_context_handle_t hContext, ur_native_handle_t *phNativeContext) {
80+
std::ignore = hContext;
81+
std::ignore = phNativeContext;
82+
DIE_NO_IMPLEMENTATION
83+
}
84+
85+
UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle(
86+
ur_native_handle_t hNativeContext, uint32_t numDevices,
87+
const ur_device_handle_t *phDevices,
88+
const ur_context_native_properties_t *pProperties,
89+
ur_context_handle_t *phContext) {
90+
std::ignore = hNativeContext;
91+
std::ignore = numDevices;
92+
std::ignore = phDevices;
93+
std::ignore = pProperties;
94+
std::ignore = phContext;
95+
96+
DIE_NO_IMPLEMENTATION
97+
}
98+
99+
UR_APIEXPORT ur_result_t UR_APICALL urContextSetExtendedDeleter(
100+
ur_context_handle_t hContext, ur_context_extended_deleter_t pfnDeleter,
101+
void *pUserData) {
102+
std::ignore = hContext;
103+
std::ignore = pfnDeleter;
104+
std::ignore = pUserData;
105+
106+
DIE_NO_IMPLEMENTATION
107+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===--------- context.hpp - Native CPU Adapter ----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <ur_api.h>
12+
13+
#include "device.hpp"
14+
15+
struct ur_context_handle_t_ {
16+
ur_context_handle_t_(ur_device_handle_t_ *phDevices) : _device{phDevices} {}
17+
18+
ur_device_handle_t _device;
19+
};

0 commit comments

Comments
 (0)