|
| 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 | +} |
0 commit comments