|
| 1 | +//===--------- usm_p2p.cpp - CUDA 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 "context.hpp" |
| 11 | + |
| 12 | +UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PEnablePeerAccessExp( |
| 13 | + ur_device_handle_t commandDevice, ur_device_handle_t peerDevice) { |
| 14 | + |
| 15 | + ur_result_t result = UR_RESULT_SUCCESS; |
| 16 | + try { |
| 17 | + ScopedContext active(commandDevice->getContext()); |
| 18 | + UR_CHECK_ERROR(cuCtxEnablePeerAccess(peerDevice->getContext(), 0)); |
| 19 | + } catch (ur_result_t err) { |
| 20 | + result = err; |
| 21 | + } |
| 22 | + return result; |
| 23 | +} |
| 24 | + |
| 25 | +UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PDisablePeerAccessExp( |
| 26 | + ur_device_handle_t commandDevice, ur_device_handle_t peerDevice) { |
| 27 | + |
| 28 | + ur_result_t result = UR_RESULT_SUCCESS; |
| 29 | + try { |
| 30 | + ScopedContext active(commandDevice->getContext()); |
| 31 | + UR_CHECK_ERROR(cuCtxDisablePeerAccess(peerDevice->getContext())); |
| 32 | + } catch (ur_result_t err) { |
| 33 | + result = err; |
| 34 | + } |
| 35 | + return result; |
| 36 | +} |
| 37 | + |
| 38 | +UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PPeerAccessGetInfoExp( |
| 39 | + ur_device_handle_t commandDevice, ur_device_handle_t peerDevice, |
| 40 | + ur_exp_peer_info_t propName, size_t propSize, void *pPropValue, |
| 41 | + size_t *pPropSizeRet) { |
| 42 | + |
| 43 | + UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet); |
| 44 | + |
| 45 | + int value; |
| 46 | + CUdevice_P2PAttribute cu_attr; |
| 47 | + try { |
| 48 | + ScopedContext active(commandDevice->getContext()); |
| 49 | + switch (propName) { |
| 50 | + case UR_EXP_PEER_INFO_UR_PEER_ACCESS_SUPPORTED: { |
| 51 | + cu_attr = CU_DEVICE_P2P_ATTRIBUTE_ACCESS_SUPPORTED; |
| 52 | + break; |
| 53 | + } |
| 54 | + case UR_EXP_PEER_INFO_UR_PEER_ATOMICS_SUPPORTED: { |
| 55 | + cu_attr = CU_DEVICE_P2P_ATTRIBUTE_NATIVE_ATOMIC_SUPPORTED; |
| 56 | + break; |
| 57 | + } |
| 58 | + default: { |
| 59 | + return UR_RESULT_ERROR_INVALID_ENUMERATION; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + UR_CHECK_ERROR(cuDeviceGetP2PAttribute( |
| 64 | + &value, cu_attr, commandDevice->get(), peerDevice->get())); |
| 65 | + } catch (ur_result_t err) { |
| 66 | + return err; |
| 67 | + } |
| 68 | + return ReturnValue(value); |
| 69 | +} |
0 commit comments