- add API to add / remove user-pointers from the tracker.
- test for thread-safety with MultiThreadtest_2 - rapid
  insertions/removal.
- add mutex to provide thread-safety.
- rename tracker interface to "memtracker_..." for consistency.
- add am_memtracker_reset, connect to hipDeviceReset.
-
Цей коміт міститься в:
Ben Sander
2016-02-11 22:03:01 -06:00
джерело 4ee2a5229b
коміт de45e2291e
4 змінених файлів з 353 додано та 54 видалено
+46 -14
Переглянути файл
@@ -15,22 +15,27 @@ namespace hc {
// This is the data that is maintained for each pointer:
struct AmPointerInfo {
bool _isDeviceMem;
void * _hostPointer;
void * _devicePointer;
size_t _sizeBytes;
hc::accelerator _acc;
unsigned _allocationFlags;
void * _hostPointer; ///< Host pointer. If host access is not allowed, NULL.
void * _devicePointer; ///< Device pointer.
size_t _sizeBytes; ///< Size of allocation.
hc::accelerator _acc; ///< Device / Accelerator to use.
bool _isInDeviceMem; ///< Memory is physically resident on a device (if false, memory is located on host)
bool _isAmManaged; ///< Memory was allocated by AM and should be freed when am_reset is called.
int _appId; ///< App-specific storage. Used by HIP to store deviceID.
unsigned _appAllocationFlags; ///< App-specific allocation flags. Used by HIP to store allocation flags.
AmPointerInfo() {};
AmPointerInfo(bool isDeviceMem, void *hostPointer, void *devicePointer, size_t sizeBytes, hc::accelerator acc, unsigned allocationFlags) :
_isDeviceMem(isDeviceMem),
AmPointerInfo(void *hostPointer, void *devicePointer, size_t sizeBytes, hc::accelerator acc, bool isInDeviceMem, bool isAmManaged) :
_hostPointer(hostPointer),
_devicePointer(devicePointer),
_sizeBytes(sizeBytes),
_acc(acc),
_allocationFlags(allocationFlags) {};
_isInDeviceMem(isInDeviceMem),
_isAmManaged(isAmManaged),
_appId(-1),
_appAllocationFlags(0) {};
};
}
@@ -73,19 +78,46 @@ am_status_t AM_free(void* ptr);
*/
am_status_t AM_copy(void* dst, const void* src, size_t size);
am_status_t AM_get_pointer_info(hc::AmPointerInfo *info, void *ptr);
/**
* Return information about tracked pointer.
*
* AM tracks pointers when they are allocated or added to tracker with am_track_pointer.
* The tracker tracks the base pointer as well as the size of the allocation, and will
* find the information for a pointer anywhere in the tracked range.
*
* @returns AM_ERROR_MISC if pointer is not currently being tracked.
* @returns AM_SUCCESS if pointer is tracked and writes info to @p info.
*
* @see AM_memtracker_add,
*/
am_status_t am_memtracker_getinfo(hc::AmPointerInfo *info, void *ptr);
//TODO-doc
am_status_t am_memtracker_update(void* ptr, int appId, unsigned allocationFlags);
// TODO-implement these:
//am_status_t AM_track_pointer(void* ptr, size_t size, bool isDeviceMem=false, unsigned allocationFlags=0x0);
//am_status_t AM_untrack_pointer(void* ptr);
am_status_t am_memtracker_add(void* ptr, size_t sizeBytes, hc::accelerator acc, bool isDeviceMem=false);
/**
* Remove the pointer from the tracker structure.
*
* @p ptr may be anywhere in a tracked memory range.
*
* @returns AM_ERROR_MISC if pointer is not found in tracker.
* @returns AM_SUCCESS if pointer is not found in tracker.
*/
am_status_t am_memtracker_remove(void* ptr);
/**
* Remove all memory allocations associated with specified accelerator.
*/
size_t am_memtracker_reset(hc::accelerator acc);
/**
* Prints the contents of the memory tracker table to stderr
*
* Intended primarily for debug purposes.
**/
void AM_print_tracker();
void am_memtracker_print();
}; // namespace hc