Skip to content

Commit d2ad7e9

Browse files
committed
libgomp: Add is_integrated_apu function to plugin/plugin-{gcn,nvptx}.c
The added function is currently '#if 0' but is planned to be used to enable self mapping automatically. Prerequisite for auto self maps is still mapping 'declare target' variables (if any, in libgomp) or converting all 'declare target' variables to 'declare target link' in the compiler (as required for 'omp requires self_maps'). include/ChangeLog: * hsa_ext_amd.h (enum hsa_amd_agent_info_s): Add HSA_AMD_AGENT_INFO_MEMORY_PROPERTIES. (enum): Add HSA_AMD_MEMORY_PROPERTY_AGENT_IS_APU. libgomp/ChangeLog: * plugin/plugin-gcn.c (is_integrated_apu): New; currently '#if 0'. * plugin/plugin-nvptx.c (is_integrated_apu): Likewise.
1 parent aaa7ac4 commit d2ad7e9

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

include/hsa_ext_amd.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,17 @@ typedef enum hsa_amd_agent_info_s {
168168
* selective workarounds for hardware errata.
169169
* The type of this attribute is uint32_t.
170170
*/
171-
HSA_AMD_AGENT_INFO_ASIC_REVISION = 0xA012
171+
HSA_AMD_AGENT_INFO_ASIC_REVISION = 0xA012,
172+
173+
/* Bitmask with memory properties of the agent. */
174+
HSA_AMD_AGENT_INFO_MEMORY_PROPERTIES = 0xA114
172175
} hsa_amd_agent_info_t;
173176

177+
178+
enum {
179+
HSA_AMD_MEMORY_PROPERTY_AGENT_IS_APU = (1 << 0)
180+
};
181+
174182
typedef struct hsa_amd_hdp_flush_s {
175183
uint32_t* HDP_MEM_FLUSH_CNTL;
176184
uint32_t* HDP_REG_FLUSH_CNTL;

libgomp/plugin/plugin-gcn.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,6 +3331,61 @@ gcn_exec (struct kernel_info *kernel,
33313331
/* }}} */
33323332
/* {{{ Generic Plugin API */
33333333

3334+
#if 0 /* TODO: Use to enable self-mapping/USM automatically. */
3335+
/* FIXME: The auto-self-map feature depends on still mapping 'declare target'
3336+
variables, even if ignoring all other mappings. Cf. PR 115279. */
3337+
3338+
/* Return TRUE if the GPU is an APU, i.e. the GPU is integrated with the CPU
3339+
such that both use the same memory controller such that mapping or memory
3340+
migration is pointless. If CHECK_XNACK is TRUE, it additionally requires
3341+
that the GPU has *no* XNACK support otherwise FALSE is returned.
3342+
3343+
In theory, enabling unified-shared memory for APUs should always work,
3344+
however, with AMD GPUs some APUs (e.g. MI300A) still require XNACK to be
3345+
enabled as it is required to handle page faults.
3346+
3347+
Thus, for unified-shared memory access, either of the following must hold:
3348+
* HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT is TRUE
3349+
This implies that all GPUs support USM access, either directly (as APU)
3350+
or via page migration. For MI300A, this is only the case if
3351+
HSA_AMD_SYSTEM_INFO_XNACK_ENABLED is TRUE.
3352+
* If the GPU an APU *and* it does not support XNACK. */
3353+
3354+
static bool
3355+
is_integrated_apu (struct agent_info *agent, bool check_xnack)
3356+
{
3357+
enum {
3358+
HSACO_ATTR_UNSUPPORTED,
3359+
HSACO_ATTR_OFF,
3360+
HSACO_ATTR_ON,
3361+
HSACO_ATTR_ANY,
3362+
HSACO_ATTR_DEFAULT
3363+
};
3364+
3365+
bool is_apu;
3366+
uint8_t mem_prop[8];
3367+
hsa_status_t status;
3368+
3369+
status = hsa_fns.hsa_agent_get_info_fn (
3370+
agent->id, (hsa_agent_info_t) HSA_AMD_AGENT_INFO_MEMORY_PROPERTIES,
3371+
mem_prop);
3372+
_Static_assert (HSA_AMD_MEMORY_PROPERTY_AGENT_IS_APU < 8,
3373+
"HSA_AMD_MEMORY_PROPERTY_AGENT_IS_APU < 8");
3374+
is_apu = (status == HSA_STATUS_SUCCESS
3375+
&& (mem_prop[0] & (1 << HSA_AMD_MEMORY_PROPERTY_AGENT_IS_APU)));
3376+
3377+
if (check_xnack)
3378+
switch(agent->device_isa)
3379+
{
3380+
#define GCN_DEVICE(name, NAME, ELF, ISA, XNACK, ...) \
3381+
case ELF: return is_apu && (XNACK == HSACO_ATTR_UNSUPPORTED);
3382+
#include "../../gcc/config/gcn/gcn-devices.def"
3383+
default: return false; /* Just to be save. */
3384+
}
3385+
return is_apu;
3386+
}
3387+
#endif
3388+
33343389
/* Return the name of the accelerator, which is "gcn". */
33353390

33363391
const char *

libgomp/plugin/plugin-nvptx.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,24 @@ nvptx_get_current_cuda_context (void)
12461246
return nvthd->ptx_dev->ctx;
12471247
}
12481248

1249+
#if 0 /* TODO: Use to enable self-mapping/USM automatically. */
1250+
/* FIXME: The auto-self-map feature depends on still mapping 'declare target'
1251+
variables, even if ignoring all other mappings. Cf. PR 115279. */
1252+
1253+
/* Return TRUE if the GPU is integrated with host memory, i.e. GPU and
1254+
host share the same memory controller. As of Oct 2025, no such
1255+
Nvidia GPU seems to exist. */
1256+
static bool
1257+
is_integrated_apu (struct ptx_device *ptx_dev)
1258+
{
1259+
int pi;
1260+
CUresult r;
1261+
r = CUDA_CALL_NOCHECK (cuDeviceGetAttribute, &pi,
1262+
CU_DEVICE_ATTRIBUTE_INTEGRATED, ptx_dev->dev);
1263+
return (r == CUDA_SUCCESS && pi == 1);
1264+
}
1265+
#endif
1266+
12491267
/* Plugin entry points. */
12501268

12511269
const char *

0 commit comments

Comments
 (0)