Updated hipPointerAttrib.cpp to pass HC backend

The changes are according to the new API function change in HC backend for HIP. Especially hipPointerGetAttribute(...)
This commit is contained in:
Aditya Avinash Atluri
2016-02-26 19:42:07 -06:00
والد 875403fec8
کامیت 4c354c9888
+21 -21
مشاهده پرونده
@@ -38,7 +38,7 @@ size_t Nbytes = 0;
// Utility Functions:
//=================================================================================================
bool operator==(const hipPointerAttribute_t &lhs, const hipPointerAttribute_t &rhs)
bool operator==(const hipPointerAttribute_t &lhs, const hipPointerAttribute_t &rhs)
{
return ((lhs.hostPointer == rhs.hostPointer) &&
(lhs.devicePointer == rhs.devicePointer) &&
@@ -50,7 +50,7 @@ bool operator==(const hipPointerAttribute_t &lhs, const hipPointerAttribute_t &r
};
bool operator!=(const hipPointerAttribute_t &lhs, const hipPointerAttribute_t &rhs)
bool operator!=(const hipPointerAttribute_t &lhs, const hipPointerAttribute_t &rhs)
{
return ! (lhs == rhs);
}
@@ -66,7 +66,7 @@ const char *memoryTypeToString(hipMemoryType memoryType)
}
void resetAttribs(hipPointerAttribute_t *attribs)
void resetAttribs(hipPointerAttribute_t *attribs)
{
attribs->hostPointer = (void*) (-1);
attribs->devicePointer = (void*) (-1);
@@ -77,9 +77,9 @@ void resetAttribs(hipPointerAttribute_t *attribs)
};
void printAttribs(const hipPointerAttribute_t *attribs)
void printAttribs(const hipPointerAttribute_t *attribs)
{
printf ("hostPointer:%p devicePointer:%p memoryType:%s deviceId:%d isManaged:%d allocationFlags:%u\n",
printf ("hostPointer:%p devicePointer:%p memoryType:%s deviceId:%d isManaged:%d allocationFlags:%u\n",
attribs->hostPointer,
attribs->devicePointer,
memoryTypeToString(attribs->memoryType),
@@ -90,7 +90,7 @@ void printAttribs(const hipPointerAttribute_t *attribs)
};
inline int zrand(int max)
inline int zrand(int max)
{
return rand() % max;
}
@@ -101,7 +101,7 @@ inline int zrand(int max)
//=================================================================================================
//--
//Run through a couple simple cases to test lookups and host pointer arithmetic:
void testSimple()
void testSimple()
{
printf ("\n");
printf ("===========================================================================\n");
@@ -135,22 +135,22 @@ void testSimple()
resetAttribs(&attribs2);
HIPCHECK( hipPointerGetAttributes(&attribs2, A_d+100));
printf("getAttr:%-20s", "A_d+100"); printAttribs(&attribs2);
HIPASSERT(attribs == attribs2);
HIPASSERT((char*)attribs.devicePointer+100 == (char*)attribs2.devicePointer);
// Corner case at end of array:
resetAttribs(&attribs2);
HIPCHECK( hipPointerGetAttributes(&attribs2, A_d+Nbytes-1));
printf("getAttr:%-20s", "A_d+NBytes-1"); printAttribs(&attribs2);
HIPASSERT(attribs == attribs2);
printf("getAttr:%-20s", "A_d+Nbytes-1"); printAttribs(&attribs2);
HIPASSERT((char*)attribs.devicePointer+Nbytes-1 == (char*)attribs2.devicePointer);
// Pointer just beyond array - must be invalid or at least a different pointer
resetAttribs(&attribs2);
e = hipPointerGetAttributes(&attribs2, A_d+Nbytes+1);
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_d+NBytes", e, hipGetErrorString(e));
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_d+NBytes", e, hipGetErrorString(e));
if (e != hipErrorInvalidValue) {
// We might have strayed into another pointer area.
printf("getAttr:%-20s", "A_d+NBytes"); printAttribs(&attribs2);
HIPASSERT(attribs.devicePointer != attribs2.devicePointer);
HIPASSERT((char*)attribs.devicePointer != (char*)attribs2.devicePointer);
}
@@ -174,26 +174,26 @@ void testSimple()
resetAttribs(&attribs2);
HIPCHECK( hipPointerGetAttributes(&attribs2, A_Pinned_h+Nbytes/2));
printf("getAttr:%-20s", "A_pinned_h+NBytes/2"); printAttribs(&attribs2);
HIPASSERT(attribs == attribs2);
HIPASSERT((char*)attribs.hostPointer+Nbytes/2 == (char*)attribs2.hostPointer);
hipFreeHost(A_Pinned_h);
e = hipPointerGetAttributes(&attribs, A_Pinned_h);
HIPASSERT(e == hipErrorInvalidValue); // Just freed the pointer, this should return an error.
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_d+NBytes", e, hipGetErrorString(e));
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_d+NBytes", e, hipGetErrorString(e));
// OS memory
printf ("\nOS-allocated memory (malloc)\n");
e = hipPointerGetAttributes(&attribs, A_OSAlloc_h);
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_OSAlloc_h", e, hipGetErrorString(e));
printf("getAttr:%-20s err=%d (%s), neg-test expected\n", "A_OSAlloc_h", e, hipGetErrorString(e));
HIPASSERT(e == hipErrorInvalidValue); // OS-allocated pointers should return hipErrorInvalidValue.
}
//---
//Reset the memory tracker (remove allocations from all known devices):
//This frees any memory allocated through the runtime.
//The routine will not release any
//The routine will not release any
void resetTracker ()
{
if (p_verbose & 0x1) {
@@ -232,8 +232,8 @@ void checkPointer(SuperPointerAttribute &ref, int major, int minor, void *pointe
HIPCHECK(e);
printf(" ref :: "); printAttribs(&ref._attrib);
printf(" getattr:: "); printAttribs(&attribs);
HIPASSERT(attribs == ref._attrib);
HIPASSERT(attribs != ref._attrib);
} else {
if (p_verbose & 0x1) {
printf("#%4d.%d GOOD:%p getattr :: ",major, minor, pointer); printAttribs(&attribs);
@@ -303,7 +303,7 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize)
size_t free, total;
HIPCHECK(hipSetDevice(i));
HIPCHECK(hipMemGetInfo(&free, &total));
printf (" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) clusterAllocTotalDevice=%lu (%4.2fMB) total=%zu (%4.2fMB)\n",
printf (" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) clusterAllocTotalDevice=%lu (%4.2fMB) total=%zu (%4.2fMB)\n",
i, free, (float)(free/1024.0/1024.0), totalDeviceAllocated[i], (float)(totalDeviceAllocated[i])/1024.0/1024.0, total, (float)(total/1024.0/1024.0));
HIPASSERT(free + totalDeviceAllocated[i] <= total);
}
@@ -432,9 +432,9 @@ void thread_noise_generator(int iters, size_t numBuffers, Dir addDir, Dir remove
//---
//Multi-thread test that is effective at catching locking errors in the alloc/dealloc/tracker.
//The query thread repeately requests information on the same block of memory.
//Meanwhile, the thread_noise_generator registers a large number of blocks, and
//Meanwhile, the thread_noise_generator registers a large number of blocks, and
//then unregisters them. This causes a large amount of rebalancing in the tree
//structure and will generate errors unless the locks in the tracker are preventing reading
//structure and will generate errors unless the locks in the tracker are preventing reading
//while writing.
void testMultiThreaded_2()
{