|
| 1 | +//===---------------- runtime.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 | +#include "ur_api.h" |
| 11 | + |
| 12 | +struct ur_adapter_handle_t_ { |
| 13 | + std::atomic<uint32_t> RefCount = 0; |
| 14 | +} Adapter; |
| 15 | + |
| 16 | +UR_APIEXPORT ur_result_t UR_APICALL urInit(ur_device_init_flags_t, |
| 17 | + ur_loader_config_handle_t) { |
| 18 | + return UR_RESULT_SUCCESS; |
| 19 | +} |
| 20 | + |
| 21 | +UR_APIEXPORT ur_result_t UR_APICALL urTearDown(void *) { |
| 22 | + return UR_RESULT_SUCCESS; |
| 23 | +} |
| 24 | + |
| 25 | +UR_APIEXPORT ur_result_t UR_APICALL urAdapterGet( |
| 26 | + uint32_t, ur_adapter_handle_t *phAdapters, uint32_t *pNumAdapters) { |
| 27 | + if (phAdapters) { |
| 28 | + Adapter.RefCount++; |
| 29 | + *phAdapters = &Adapter; |
| 30 | + } |
| 31 | + if (pNumAdapters) { |
| 32 | + *pNumAdapters = 1; |
| 33 | + } |
| 34 | + return UR_RESULT_SUCCESS; |
| 35 | +} |
| 36 | + |
| 37 | +UR_APIEXPORT ur_result_t UR_APICALL urAdapterRelease(ur_adapter_handle_t) { |
| 38 | + Adapter.RefCount--; |
| 39 | + return UR_RESULT_SUCCESS; |
| 40 | +} |
| 41 | + |
| 42 | +UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) { |
| 43 | + Adapter.RefCount++; |
| 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