175 строки
5.5 KiB
C++
175 строки
5.5 KiB
C++
/*
|
|
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
*/
|
|
|
|
#include <hc_am.hpp>
|
|
|
|
#include "hip_runtime.h"
|
|
#include "hcc_detail/hip_hcc.h"
|
|
#include "hcc_detail/trace_helper.h"
|
|
|
|
/**
|
|
* HCC returns 0 in *canAccessPeer ; Need to update this function when RT supports P2P
|
|
*/
|
|
//---
|
|
hipError_t hipDeviceCanAccessPeer (int* canAccessPeer, int deviceId, int peerDeviceId)
|
|
{
|
|
HIP_INIT_API(canAccessPeer, deviceId, peerDeviceId);
|
|
|
|
hipError_t err = hipSuccess;
|
|
|
|
auto thisDevice = ihipGetDevice(deviceId);
|
|
auto peerDevice = ihipGetDevice(peerDeviceId);
|
|
|
|
if ((thisDevice != NULL) && (peerDevice != NULL)) {
|
|
if (deviceId == peerDeviceId) {
|
|
*canAccessPeer = 0;
|
|
} else {
|
|
#if USE_PEER_TO_PEER>=2
|
|
*canAccessPeer = peerDevice->_acc.get_is_peer(thisDevice->_acc);
|
|
#else
|
|
*canAccessPeer = 0;
|
|
#endif
|
|
}
|
|
|
|
} else {
|
|
*canAccessPeer = 0;
|
|
err = hipErrorInvalidDevice;
|
|
}
|
|
|
|
|
|
return ihipLogStatus(err);
|
|
}
|
|
|
|
|
|
//---
|
|
// Disable visibility of this device into memory allocated on peer device.
|
|
// Remove this device from peer device peerlist.
|
|
hipError_t hipDeviceDisablePeerAccess (int peerDeviceId)
|
|
{
|
|
HIP_INIT_API(peerDeviceId);
|
|
|
|
hipError_t err = hipSuccess;
|
|
|
|
auto thisDevice = ihipGetTlsDefaultDevice();
|
|
auto peerDevice = ihipGetDevice(peerDeviceId);
|
|
if ((thisDevice != NULL) && (peerDevice != NULL)) {
|
|
#if USE_PEER_TO_PEER>=2
|
|
// Return true if thisDevice can access peerDevice's memory:
|
|
bool canAccessPeer = peerDevice->_acc.get_is_peer(thisDevice->_acc);
|
|
#else
|
|
bool canAccessPeer = 0;
|
|
#endif
|
|
|
|
if (! canAccessPeer) {
|
|
err = hipErrorInvalidDevice; // P2P not allowed between these devices.
|
|
} else if (thisDevice == peerDevice) {
|
|
err = hipErrorInvalidDevice; // Can't disable peer access to self.
|
|
} else {
|
|
LockedAccessor_DeviceCrit_t peerCrit(peerDevice->criticalData());
|
|
bool changed = peerCrit->removePeer(thisDevice);
|
|
if (changed) {
|
|
#if USE_PEER_TO_PEER>=3
|
|
// Update the peers for all memory already saved in the tracker:
|
|
am_memtracker_update_peers(peerDevice->_acc, peerCrit->peerCnt(), peerCrit->peerAgents());
|
|
#endif
|
|
} else {
|
|
err = hipErrorPeerAccessNotEnabled; // never enabled P2P access.
|
|
}
|
|
}
|
|
} else {
|
|
err = hipErrorInvalidDevice;
|
|
}
|
|
|
|
return ihipLogStatus(err);
|
|
};
|
|
|
|
|
|
//---
|
|
// Allow the current device to see all memory allocated on peerDevice.
|
|
// This should add this device to the peer-device peer list.
|
|
hipError_t hipDeviceEnablePeerAccess (int peerDeviceId, unsigned int flags)
|
|
{
|
|
HIP_INIT_API(peerDeviceId, flags);
|
|
|
|
hipError_t err = hipSuccess;
|
|
if (flags != 0) {
|
|
err = hipErrorInvalidValue;
|
|
} else {
|
|
auto thisDevice = ihipGetTlsDefaultDevice();
|
|
auto peerDevice = ihipGetDevice(peerDeviceId);
|
|
if (thisDevice == peerDevice) {
|
|
err = hipErrorInvalidDevice; // Can't enable peer access to self.
|
|
} else if ((thisDevice != NULL) && (peerDevice != NULL)) {
|
|
LockedAccessor_DeviceCrit_t peerCrit(peerDevice->criticalData());
|
|
bool isNewPeer = peerCrit->addPeer(thisDevice);
|
|
if (isNewPeer) {
|
|
#if USE_PEER_TO_PEER>=3
|
|
am_memtracker_update_peers(peerDevice->_acc, peerCrit->peerCnt(), peerCrit->peerAgents());
|
|
#endif
|
|
} else {
|
|
err = hipErrorPeerAccessAlreadyEnabled;
|
|
}
|
|
} else {
|
|
err = hipErrorInvalidDevice;
|
|
}
|
|
}
|
|
|
|
return ihipLogStatus(err);
|
|
}
|
|
|
|
|
|
//---
|
|
hipError_t hipMemcpyPeer (void* dst, int dstDevice, const void* src, int srcDevice, size_t sizeBytes)
|
|
{
|
|
HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes);
|
|
|
|
// HCC has a unified memory architecture so device specifiers are not required.
|
|
return hipMemcpy(dst, src, sizeBytes, hipMemcpyDefault);
|
|
};
|
|
|
|
|
|
/**
|
|
* This function uses a synchronous copy
|
|
*/
|
|
//---
|
|
hipError_t hipMemcpyPeerAsync (void* dst, int dstDevice, const void* src, int srcDevice, size_t sizeBytes, hipStream_t stream)
|
|
{
|
|
HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes, stream);
|
|
// HCC has a unified memory architecture so device specifiers are not required.
|
|
return hipMemcpyAsync(dst, src, sizeBytes, hipMemcpyDefault, stream);
|
|
};
|
|
|
|
|
|
/**
|
|
* @return #hipSuccess
|
|
*/
|
|
//---
|
|
hipError_t hipDriverGetVersion(int *driverVersion)
|
|
{
|
|
HIP_INIT_API(driverVersion);
|
|
|
|
if (driverVersion) {
|
|
*driverVersion = 4;
|
|
}
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
}
|
|
|
|
|