Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature for locking host memory #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/hc_am.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,9 @@ void am_memtracker_print();
void am_memtracker_sizeinfo(const hc::accelerator &acc, size_t *deviceMemSize, size_t *hostMemSize, size_t *userMemSize);


am_status_t am_memtracker_host_memory_lock(hc::accelerator &acc, void *ptr, size_t size);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityaatluri As these two new functions are public APIs and would supposedly be invoked by user applications, could you help provide some comments for them?


am_status_t am_memtracker_host_memory_unlock(const hc::accelerator &acc, void *ptr);

}; // namespace hc

36 changes: 36 additions & 0 deletions lib/hsa/hc_am.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "hc_am.hpp"
#include "hsa.h"
#include "hsa_ext_amd.h"

#define DB_TRACKER 0

Expand Down Expand Up @@ -321,6 +322,41 @@ void am_memtracker_sizeinfo(const hc::accelerator &acc, size_t *deviceMemSize, s
g_amPointerTracker.readerUnlock();
}

am_status_t am_memtracker_host_memory_lock(hc::accelerator &acc, void *hostPtr, size_t size)
{
am_status_t am_status;
void *devPtr;
hsa_status_t status = hsa_amd_memory_lock(hostPtr, size, static_cast<hsa_agent_t*>(acc.get_default_view().get_hsa_agent()), 1, &devPtr);
if(status == HSA_STATUS_SUCCESS)
{
// hc::AmPointerInfo amPointerInfo(hostPtr, devPtr, size, acc, true, false);
g_amPointerTracker.insert(devPtr, hc::AmPointerInfo(hostPtr/*hostPointer*/, devPtr /*devicePointer*/, size, acc, true/*isDevice*/, false /*isAMManaged*/));

am_status = AM_SUCCESS;
}
return am_status;
}

am_status_t am_memtracker_host_memory_unlock(const hc::accelerator &acc, void *hostPtr)
{
am_status_t am_status = AM_ERROR_MISC;
if(hostPtr != NULL)
{
hsa_status_t status = hsa_amd_memory_unlock(hostPtr);
if(status == HSA_STATUS_SUCCESS){
int numRemoved = g_amPointerTracker.remove(hostPtr) ;
if (numRemoved == 0) {
am_status = AM_ERROR_MISC;
}
}else{
am_status = AM_ERROR_MISC;
}
}else
{
am_status = AM_ERROR_MISC;
}
return am_status;
}

//---
size_t am_memtracker_reset(const hc::accelerator &acc)
Expand Down