-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1059 from martygrant/martin/moveNativeCPUAdapterToUR
[NATIVECPU] Move Native CPU adapter to UR.
- Loading branch information
Showing
33 changed files
with
3,493 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
Language: Cpp | ||
BasedOnStyle: LLVM | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}/../../" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
//===--------- command_buffer.cpp - NativeCPU 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. | ||
/// Issue raised for this comment in | ||
/// https://github.com/oneapi-src/unified-runtime/issues/1064 | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.