Skip to content

Commit

Permalink
Merge pull request #158 from RadeonOpenCompute/hsa_coherent_alloc
Browse files Browse the repository at this point in the history
Add options to alloc HSA Coherent system memory
  • Loading branch information
whchung authored Nov 10, 2016
2 parents 7997b98 + 8858896 commit 79608e4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
24 changes: 24 additions & 0 deletions include/hc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,18 @@ class accelerator_view {
return pQueue->getHSAAMHostRegion();
}

/**
* Returns an opaque handle which points to the AM system region on the HSA agent.
* This region can be used to allocate finegrained system memory which is accessible from the
* specified accelerator.
*
* @return An opaque handle of the region, if the accelerator is based
* on HSA. NULL otherwise.
*/
void* get_hsa_am_finegrained_system_region() {
return pQueue->getHSACoherentAMHostRegion();
}

/**
* Returns an opaque handle which points to the Kernarg region on the HSA
* agent.
Expand Down Expand Up @@ -876,6 +888,18 @@ class accelerator
return get_default_view().get_hsa_am_system_region();
}

/**
* Returns an opaque handle which points to the AM system region on the HSA agent.
* This region can be used to allocate finegrained system memory which is accessible from the
* specified accelerator.
*
* @return An opaque handle of the region, if the accelerator is based
* on HSA. NULL otherwise.
*/
void* get_hsa_am_finegrained_system_region() const {
return get_default_view().get_hsa_am_finegrained_system_region();
}

/**
* Returns an opaque handle which points to the Kernarg region on the HSA
* agent.
Expand Down
1 change: 1 addition & 0 deletions include/hc_am.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ typedef int am_status_t;

// Flags for am_alloc API:
#define amHostPinned 0x1
#define amHostCoherent 0x2


namespace hc {
Expand Down
2 changes: 2 additions & 0 deletions include/kalmar_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class KalmarQueue
virtual void* getHSAAMRegion() { return nullptr; }

virtual void* getHSAAMHostRegion() { return nullptr; }

virtual void* getHSACoherentAMHostRegion() { return nullptr; }

/// get kernarg region handle
virtual void* getHSAKernargRegion() { return nullptr; }
Expand Down
4 changes: 3 additions & 1 deletion lib/hsa/hc_am.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ auto_voidp am_alloc(size_t sizeBytes, hc::accelerator &acc, unsigned flags)
hsa_amd_memory_pool_t *alloc_region;
if (flags & amHostPinned) {
alloc_region = static_cast<hsa_amd_memory_pool_t*>(acc.get_hsa_am_system_region());
} else {
} else if (flags & amHostCoherent) {
alloc_region = static_cast<hsa_amd_memory_pool_t*>(acc.get_hsa_am_finegrained_system_region());
}else {
alloc_region = static_cast<hsa_amd_memory_pool_t*>(acc.get_hsa_am_region());
}

Expand Down
16 changes: 15 additions & 1 deletion lib/hsa/mcwamp_hsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ struct pool_iterator
{
hsa_amd_memory_pool_t _am_memory_pool;
hsa_amd_memory_pool_t _am_host_memory_pool;
hsa_amd_memory_pool_t _am_host_coherent_memory_pool;

hsa_amd_memory_pool_t _kernarg_memory_pool;
hsa_amd_memory_pool_t _finegrained_system_memory_pool;
Expand Down Expand Up @@ -1368,6 +1369,8 @@ class HSAQueue final : public KalmarQueue
void* getHostAgent() override;

void* getHSAAMRegion() override;

void* getHSACoherentHostRegion() override;

void* getHSAAMHostRegion() override;

Expand Down Expand Up @@ -1847,6 +1850,10 @@ class HSADevice final : public KalmarDevice
ri._am_host_memory_pool = (ri._found_coarsegrained_system_memory_pool)
? ri._coarsegrained_system_memory_pool
: ri._finegrained_system_memory_pool;

ri._am_host_coherent_memory_pool = (ri._found_finegrained_system_memory_pool)
? ri._finegrained_system_memory_pool
: ri._coarsegrained_system_memory_pool;

/// Query the maximum number of work-items in a workgroup
status = hsa_agent_get_info(agent, HSA_AGENT_INFO_WORKGROUP_MAX_SIZE, &workgroup_max_size);
Expand Down Expand Up @@ -2210,6 +2217,10 @@ class HSADevice final : public KalmarDevice
return ri._am_host_memory_pool;
}

hsa_amd_memory_pool_t& getHSACoherentHostRegion() {
return ri._am_host_coherent_memory_pool;
}

hsa_amd_memory_pool_t& getHSAAMRegion() {
return ri._am_memory_pool;
}
Expand Down Expand Up @@ -2969,7 +2980,10 @@ inline void*
HSAQueue::getHSAAMRegion() override {
return static_cast<void*>(&(static_cast<HSADevice*>(getDev())->getHSAAMRegion()));
}

inline void*
HSAQueue::getHSACoherentHostRegion() override {
return static_cast<void*>(&(static_cast<HSADevice*>(getDev())->getHSACoherentHostRegion()));
}
inline void*
HSAQueue::getHSAAMHostRegion() override {
return static_cast<void*>(&(static_cast<HSADevice*>(getDev())->getHSAAMHostRegion()));
Expand Down

0 comments on commit 79608e4

Please sign in to comment.