Use memtracker 'appID' to store deviceID associated with ptr

Tá an tiomantas seo le fáil i:
Ben Sander
2016-02-11 23:07:19 -06:00
tuismitheoir de45e2291e
tiomantas 00fd172c64
D'athraigh 2 comhad le 70 breiseanna agus 29 scriosta
+11 -1
Féach ar an gComhad
@@ -286,7 +286,17 @@ am_status_t am_memtracker_getinfo(hc::AmPointerInfo *info, void *ptr)
}
am_status_t am_memtracker_update(void* ptr, int appId, unsigned allocationFlags);
am_status_t am_memtracker_update(void* ptr, int appId, unsigned allocationFlags)
{
auto iter = g_amPointerTracker.find(ptr);
if (iter != g_amPointerTracker.end()) {
iter->second._appId = appId;
iter->second._appAllocationFlags = allocationFlags;
return AM_SUCCESS;
} else {
return AM_ERROR_MISC;
}
}
am_status_t am_memtracker_add(void* ptr, size_t sizeBytes, hc::accelerator acc, bool isDeviceMem)
+59 -28
Féach ar an gComhad
@@ -1295,18 +1295,11 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t *attributes, void* ptr)
attributes->hostPointer = amPointerInfo._hostPointer;
attributes->devicePointer = amPointerInfo._devicePointer;
attributes->isManaged = 0;
attributes->allocationFlags = amPointerInfo._appAllocationFlags;
attributes->device = amPointerInfo._appId;
attributes->device = -1;
e = hipErrorInvalidDevice;
for (int i=0; i<g_devices.size(); i++) {
if (g_devices[i]._acc == amPointerInfo._acc) {
attributes->device = i;
e = hipSuccess;
break;
}
}
} else {
attributes->memoryType = hipMemoryTypeDevice;
attributes->hostPointer = 0;
@@ -1322,6 +1315,36 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t *attributes, void* ptr)
}
// TODO - test this function:
/**
* @returns #hipSuccess,
* @returns #hipErrorInvalidValue if flags are not 0
* @returns #hipErrorMemoryAllocation if hostPointer is not a tracked allocation.
*/
hipError_t hipHostGetDevicePointer(void **devicePointer, void *hostPointer, unsigned flags)
{
std::call_once(hip_initialized, ihipInit);
hipError_t e = hipSuccess;
// Flags must be 0:
if (flags == 0) {
e = hipErrorInvalidValue;
} else {
hc::AmPointerInfo amPointerInfo;
am_status_t status = hc::am_memtracker_getinfo(&amPointerInfo, hostPointer);
if (status == AM_SUCCESS) {
*devicePointer = amPointerInfo._devicePointer;
} else {
e = hipErrorMemoryAllocation;
*devicePointer = NULL;
}
}
return ihipLogStatus(e);
}
// kernel for launching memcpy operations:
template <typename T>
@@ -1398,24 +1421,31 @@ ihipMemsetKernel(hipStream_t stream, T * ptr, T val, size_t sizeBytes)
}
//---
/**
* @returns #hipSuccess #hipErrorMemoryAllocation
*/
hipError_t hipMalloc(void** ptr, size_t sizeBytes)
{
std::call_once(hip_initialized, ihipInit);
hipError_t hip_status = hipSuccess;
const unsigned am_flags = 0;
*ptr = hc::AM_alloc(sizeBytes, ihipGetTlsDefaultDevice()->_acc, am_flags);
auto device = ihipGetTlsDefaultDevice();
if (sizeBytes && (*ptr == NULL)) {
hip_status = hipErrorMemoryAllocation;
if (device) {
const unsigned am_flags = 0;
*ptr = hc::AM_alloc(sizeBytes, device->_acc, am_flags);
if (sizeBytes && (*ptr == NULL)) {
hip_status = hipErrorMemoryAllocation;
} else {
hc::am_memtracker_update(*ptr, device->_device_index, 0);
}
} else {
hip_status = hipSuccess;
hip_status = hipErrorMemoryAllocation;
}
ihipLogStatus(hip_status);
return hip_status;
return ihipLogStatus(hip_status);
}
@@ -1423,23 +1453,24 @@ hipError_t hipMallocHost(void** ptr, size_t sizeBytes)
{
std::call_once(hip_initialized, ihipInit);
hipError_t hip_status = hipSuccess;
#if USE_PINNED_HOST
const unsigned am_flags = amHostPinned;
auto device = ihipGetTlsDefaultDevice();
*ptr = hc::AM_alloc(sizeBytes, ihipGetTlsDefaultDevice()->_acc, am_flags);
hipError_t hip_status = hipSuccess;
if (sizeBytes && (*ptr == NULL)) {
hip_status = hipErrorMemoryAllocation;
} else {
hip_status = hipSuccess;
if (device) {
*ptr = hc::AM_alloc(sizeBytes, device->_acc, am_flags);
if (sizeBytes && (*ptr == NULL)) {
hip_status = hipErrorMemoryAllocation;
} else {
hc::am_memtracker_update(*ptr, device->_device_index, 0);
}
tprintf (TRACE_MEM, " %s: pinned ptr=%p\n", __func__, *ptr);
}
tprintf (TRACE_MEM, " %s: pinned ptr=%p\n", __func__, *ptr);
ihipLogStatus(hip_status);
return hip_status;
return ihipLogStatus(hip_status);
#else
// TODO-hcc remove-me