Skip to content

Commit 15ed5c0

Browse files
committed
[LIBOMPTARGET] Adding AMD to llvm-omp-device-info
Adding device information print for AMD devices on the `llvm-omp-device-info` command line tool. The output is inspired by the rocminfo command line tool. This commit adds missing HSA functions, enums and structs needed to query additional information from the HSA agents. A generic message for the `generic-elf-64bit` plugin is also added Example of an output: ``` llvm-omp-device-info Device (0): This is a generic-elf-64bit device Device (1): This is a generic-elf-64bit device Device (2): This is a generic-elf-64bit device Device (3): This is a generic-elf-64bit device Device (4): HSA Runtime Version: 1.1 HSA OpenMP Device Number: 0 Device Name: gfx906 Vendor Name: AMD Device Type: GPU Max Queues: 128 Queue Min Size: 64 Queue Max Size: 131072 Cache: L0: 16384 bytes L1: 8388608 bytes Cacheline Size: 64 Max Clock Freq(MHz): 1725 Compute Units: 60 SIMD per CU: 4 Fast F16 Operation: TRUE Wavefront Size: 64 Workgroup Max Size: 1024 Workgroup Max Size per Dimension: x: 1024 y: 1024 z: 1024 Max Waves Per CU: 40 Max Work-item Per CU: 2560 Grid Max Size: 4294967295 Grid Max Size per Dimension: x: 4294967295 y: 4294967295 z: 4294967295 Max fbarriers/Workgrp: 32 Memory Pools: Pool GLOBAL; FLAGS: COARSE GRAINED, : Size: 34342961152 bytes Allocatable: TRUE Runtime Alloc Granule: 4096 bytes Runtime Alloc alignment: 4096 bytes Accessable by all: FALSE Pool GLOBAL; FLAGS: FINE GRAINED, : Size: 34342961152 bytes Allocatable: TRUE Runtime Alloc Granule: 4096 bytes Runtime Alloc alignment: 4096 bytes Accessable by all: FALSE Pool GROUP: Size: 65536 bytes Allocatable: FALSE Runtime Alloc Granule: 0 bytes Runtime Alloc alignment: 0 bytes Accessable by all: FALSE Device (5): HSA Runtime Version: 1.1 HSA OpenMP Device Number: 1 Device Name: gfx906 Vendor Name: AMD Device Type: GPU Max Queues: 128 Queue Min Size: 64 Queue Max Size: 131072 Cache: L0: 16384 bytes L1: 8388608 bytes Cacheline Size: 64 Max Clock Freq(MHz): 1725 Compute Units: 60 SIMD per CU: 4 Fast F16 Operation: TRUE Wavefront Size: 64 Workgroup Max Size: 1024 Workgroup Max Size per Dimension: x: 1024 y: 1024 z: 1024 Max Waves Per CU: 40 Max Work-item Per CU: 2560 Grid Max Size: 4294967295 Grid Max Size per Dimension: x: 4294967295 y: 4294967295 z: 4294967295 Max fbarriers/Workgrp: 32 Memory Pools: Pool GLOBAL; FLAGS: COARSE GRAINED, : Size: 34342961152 bytes Allocatable: TRUE Runtime Alloc Granule: 4096 bytes Runtime Alloc alignment: 4096 bytes Accessable by all: FALSE Pool GLOBAL; FLAGS: FINE GRAINED, : Size: 34342961152 bytes Allocatable: TRUE Runtime Alloc Granule: 4096 bytes Runtime Alloc alignment: 4096 bytes Accessable by all: FALSE Pool GROUP: Size: 65536 bytes Allocatable: FALSE Runtime Alloc Granule: 0 bytes Runtime Alloc alignment: 0 bytes Accessable by all: FALSE Device (6): HSA Runtime Version: 1.1 HSA OpenMP Device Number: 2 Device Name: gfx906 Vendor Name: AMD Device Type: GPU Max Queues: 128 Queue Min Size: 64 Queue Max Size: 131072 Cache: L0: 16384 bytes L1: 8388608 bytes Cacheline Size: 64 Max Clock Freq(MHz): 1725 Compute Units: 60 SIMD per CU: 4 Fast F16 Operation: TRUE Wavefront Size: 64 Workgroup Max Size: 1024 Workgroup Max Size per Dimension: x: 1024 y: 1024 z: 1024 Max Waves Per CU: 40 Max Work-item Per CU: 2560 Grid Max Size: 4294967295 Grid Max Size per Dimension: x: 4294967295 y: 4294967295 z: 4294967295 Max fbarriers/Workgrp: 32 Memory Pools: Pool GLOBAL; FLAGS: COARSE GRAINED, : Size: 34342961152 bytes Allocatable: TRUE Runtime Alloc Granule: 4096 bytes Runtime Alloc alignment: 4096 bytes Accessable by all: FALSE Pool GLOBAL; FLAGS: FINE GRAINED, : Size: 34342961152 bytes Allocatable: TRUE Runtime Alloc Granule: 4096 bytes Runtime Alloc alignment: 4096 bytes Accessable by all: FALSE Pool GROUP: Size: 65536 bytes Allocatable: FALSE Runtime Alloc Granule: 0 bytes Runtime Alloc alignment: 0 bytes Accessable by all: FALSE Device (7): HSA Runtime Version: 1.1 HSA OpenMP Device Number: 3 Device Name: gfx906 Vendor Name: AMD Device Type: GPU Max Queues: 128 Queue Min Size: 64 Queue Max Size: 131072 Cache: L0: 16384 bytes L1: 8388608 bytes Cacheline Size: 64 Max Clock Freq(MHz): 1725 Compute Units: 60 SIMD per CU: 4 Fast F16 Operation: TRUE Wavefront Size: 64 Workgroup Max Size: 1024 Workgroup Max Size per Dimension: x: 1024 y: 1024 z: 1024 Max Waves Per CU: 40 Max Work-item Per CU: 2560 Grid Max Size: 4294967295 Grid Max Size per Dimension: x: 4294967295 y: 4294967295 z: 4294967295 Max fbarriers/Workgrp: 32 Memory Pools: Pool GLOBAL; FLAGS: COARSE GRAINED, : Size: 34342961152 bytes Allocatable: TRUE Runtime Alloc Granule: 4096 bytes Runtime Alloc alignment: 4096 bytes Accessable by all: FALSE Pool GLOBAL; FLAGS: FINE GRAINED, : Size: 34342961152 bytes Allocatable: TRUE Runtime Alloc Granule: 4096 bytes Runtime Alloc alignment: 4096 bytes Accessable by all: FALSE Pool GROUP: Size: 65536 bytes Allocatable: FALSE Runtime Alloc Granule: 0 bytes Runtime Alloc alignment: 0 bytes Accessable by all: FALSE ``` Differential Revision: https://reviews.llvm.org/D126836
1 parent 0abb472 commit 15ed5c0

File tree

5 files changed

+327
-0
lines changed

5 files changed

+327
-0
lines changed

openmp/libomptarget/plugins/amdgpu/dynamic_hsa/hsa.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ DLWRAP_INTERNAL(hsa_init, 0);
2323

2424
DLWRAP(hsa_status_string, 2);
2525
DLWRAP(hsa_shut_down, 0);
26+
DLWRAP(hsa_system_get_info, 2);
2627
DLWRAP(hsa_agent_get_info, 3);
28+
DLWRAP(hsa_isa_get_info_alt, 3);
2729
DLWRAP(hsa_iterate_agents, 2);
30+
DLWRAP(hsa_agent_iterate_isas, 3);
2831
DLWRAP(hsa_signal_create, 4);
2932
DLWRAP(hsa_signal_destroy, 1);
3033
DLWRAP(hsa_signal_store_relaxed, 2);

openmp/libomptarget/plugins/amdgpu/dynamic_hsa/hsa.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,58 @@ typedef enum {
5555
HSA_DEVICE_TYPE_DSP = 2
5656
} hsa_device_type_t;
5757

58+
typedef enum {
59+
HSA_ISA_INFO_NAME = 1,
60+
} hsa_isa_info_t;
61+
5862
typedef enum {
5963
HSA_AGENT_INFO_NAME = 0,
64+
HSA_AGENT_INFO_VENDOR_NAME = 1,
6065
HSA_AGENT_INFO_PROFILE = 4,
6166
HSA_AGENT_INFO_WAVEFRONT_SIZE = 6,
6267
HSA_AGENT_INFO_WORKGROUP_MAX_DIM = 7,
68+
HSA_AGENT_INFO_WORKGROUP_MAX_SIZE = 8,
6369
HSA_AGENT_INFO_GRID_MAX_DIM = 9,
70+
HSA_AGENT_INFO_GRID_MAX_SIZE = 10,
71+
HSA_AGENT_INFO_FBARRIER_MAX_SIZE = 11,
72+
HSA_AGENT_INFO_QUEUES_MAX = 12,
73+
HSA_AGENT_INFO_QUEUE_MIN_SIZE = 13,
6474
HSA_AGENT_INFO_QUEUE_MAX_SIZE = 14,
6575
HSA_AGENT_INFO_DEVICE = 17,
76+
HSA_AGENT_INFO_CACHE_SIZE = 18,
77+
HSA_AGENT_INFO_FAST_F16_OPERATION = 24,
6678
} hsa_agent_info_t;
6779

80+
typedef enum {
81+
HSA_SYSTEM_INFO_VERSION_MAJOR = 0,
82+
HSA_SYSTEM_INFO_VERSION_MINOR = 1,
83+
} hsa_system_info_t;
84+
85+
typedef struct hsa_region_s {
86+
uint64_t handle;
87+
} hsa_region_t;
88+
89+
typedef struct hsa_isa_s {
90+
uint64_t handle;
91+
} hsa_isa_t;
92+
93+
hsa_status_t hsa_system_get_info(hsa_system_info_t attribute, void *value);
94+
6895
hsa_status_t hsa_agent_get_info(hsa_agent_t agent, hsa_agent_info_t attribute,
6996
void *value);
7097

98+
hsa_status_t hsa_isa_get_info_alt(hsa_isa_t isa, hsa_isa_info_t attribute,
99+
void *value);
100+
71101
hsa_status_t hsa_iterate_agents(hsa_status_t (*callback)(hsa_agent_t agent,
72102
void *data),
73103
void *data);
74104

105+
hsa_status_t hsa_agent_iterate_isas(hsa_agent_t agent,
106+
hsa_status_t (*callback)(hsa_isa_t isa,
107+
void *data),
108+
void *data);
109+
75110
typedef struct hsa_signal_s {
76111
uint64_t handle;
77112
} hsa_signal_t;

openmp/libomptarget/plugins/amdgpu/dynamic_hsa/hsa_ext_amd.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,20 @@ typedef enum hsa_amd_memory_pool_global_flag_s {
2929
} hsa_amd_memory_pool_global_flag_t;
3030

3131
typedef enum {
32+
HSA_AMD_SEGMENT_GLOBAL = 0,
33+
HSA_AMD_SEGMENT_READONLY = 1,
34+
HSA_AMD_SEGMENT_PRIVATE = 2,
35+
HSA_AMD_SEGMENT_GROUP = 3,
36+
} hsa_amd_segment_t;
37+
38+
typedef enum {
39+
HSA_AMD_MEMORY_POOL_INFO_SEGMENT = 0,
3240
HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS = 1,
3341
HSA_AMD_MEMORY_POOL_INFO_SIZE = 2,
3442
HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED = 5,
43+
HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_GRANULE = 6,
44+
HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALIGNMENT = 7,
45+
HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL = 15,
3546
} hsa_amd_memory_pool_info_t;
3647

3748
typedef enum {
@@ -43,7 +54,13 @@ typedef enum {
4354
} hsa_amd_memory_pool_access_t;
4455

4556
typedef enum hsa_amd_agent_info_s {
57+
HSA_AMD_AGENT_INFO_CACHELINE_SIZE = 0xA001,
4658
HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT = 0xA002,
59+
HSA_AMD_AGENT_INFO_MAX_CLOCK_FREQUENCY = 0xA003,
60+
HSA_AMD_AGENT_INFO_PRODUCT_NAME = 0xA009,
61+
HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU = 0xA00A,
62+
HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU = 0xA00B,
63+
HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES = 0xA010
4764
} hsa_amd_agent_info_t;
4865

4966
hsa_status_t hsa_amd_memory_pool_get_info(hsa_amd_memory_pool_t memory_pool,

openmp/libomptarget/plugins/amdgpu/src/rtl.cpp

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ static void callbackQueue(hsa_status_t status, hsa_queue_t *source,
282282

283283
namespace core {
284284
namespace {
285+
286+
bool checkResult(hsa_status_t Err, const char *ErrMsg) {
287+
if (Err == HSA_STATUS_SUCCESS)
288+
return true;
289+
290+
REPORT("%s", ErrMsg);
291+
REPORT("%s", get_error_string(Err));
292+
return false;
293+
}
294+
285295
void packet_store_release(uint32_t *packet, uint16_t header, uint16_t rest) {
286296
__atomic_store_n(packet, header | (rest << 16), __ATOMIC_RELEASE);
287297
}
@@ -542,6 +552,256 @@ class RTLDeviceInfoTy : HSALifetime {
542552
return freesignalpool_memcpy(dest, src, size, impl_memcpy_h2d, deviceId);
543553
}
544554

555+
static void printDeviceInfo(int32_t device_id, hsa_agent_t agent) {
556+
char TmpChar[1000];
557+
uint16_t major, minor;
558+
uint32_t TmpUInt;
559+
uint32_t TmpUInt2;
560+
uint32_t CacheSize[4];
561+
bool TmpBool;
562+
uint16_t workgroupMaxDim[3];
563+
hsa_dim3_t gridMaxDim;
564+
565+
// Getting basic information about HSA and Device
566+
core::checkResult(
567+
hsa_system_get_info(HSA_SYSTEM_INFO_VERSION_MAJOR, &major),
568+
"Error from hsa_system_get_info when obtaining "
569+
"HSA_SYSTEM_INFO_VERSION_MAJOR\n");
570+
core::checkResult(
571+
hsa_system_get_info(HSA_SYSTEM_INFO_VERSION_MINOR, &minor),
572+
"Error from hsa_system_get_info when obtaining "
573+
"HSA_SYSTEM_INFO_VERSION_MINOR\n");
574+
printf(" HSA Runtime Version: \t\t%u.%u \n", major, minor);
575+
printf(" HSA OpenMP Device Number: \t\t%d \n", device_id);
576+
core::checkResult(
577+
hsa_agent_get_info(
578+
agent, (hsa_agent_info_t)HSA_AMD_AGENT_INFO_PRODUCT_NAME, TmpChar),
579+
"Error returned from hsa_agent_get_info when obtaining "
580+
"HSA_AMD_AGENT_INFO_PRODUCT_NAME\n");
581+
printf(" Product Name: \t\t\t%s \n", TmpChar);
582+
core::checkResult(hsa_agent_get_info(agent, HSA_AGENT_INFO_NAME, TmpChar),
583+
"Error returned from hsa_agent_get_info when obtaining "
584+
"HSA_AGENT_INFO_NAME\n");
585+
printf(" Device Name: \t\t\t%s \n", TmpChar);
586+
core::checkResult(
587+
hsa_agent_get_info(agent, HSA_AGENT_INFO_VENDOR_NAME, TmpChar),
588+
"Error returned from hsa_agent_get_info when obtaining "
589+
"HSA_AGENT_INFO_NAME\n");
590+
printf(" Vendor Name: \t\t\t%s \n", TmpChar);
591+
hsa_device_type_t devType;
592+
core::checkResult(
593+
hsa_agent_get_info(agent, HSA_AGENT_INFO_DEVICE, &devType),
594+
"Error returned from hsa_agent_get_info when obtaining "
595+
"HSA_AGENT_INFO_DEVICE\n");
596+
printf(" Device Type: \t\t\t%s \n",
597+
devType == HSA_DEVICE_TYPE_CPU
598+
? "CPU"
599+
: (devType == HSA_DEVICE_TYPE_GPU
600+
? "GPU"
601+
: (devType == HSA_DEVICE_TYPE_DSP ? "DSP" : "UNKNOWN")));
602+
core::checkResult(
603+
hsa_agent_get_info(agent, HSA_AGENT_INFO_QUEUES_MAX, &TmpUInt),
604+
"Error returned from hsa_agent_get_info when obtaining "
605+
"HSA_AGENT_INFO_QUEUES_MAX\n");
606+
printf(" Max Queues: \t\t\t%u \n", TmpUInt);
607+
core::checkResult(
608+
hsa_agent_get_info(agent, HSA_AGENT_INFO_QUEUE_MIN_SIZE, &TmpUInt),
609+
"Error returned from hsa_agent_get_info when obtaining "
610+
"HSA_AGENT_INFO_QUEUE_MIN_SIZE\n");
611+
printf(" Queue Min Size: \t\t\t%u \n", TmpUInt);
612+
core::checkResult(
613+
hsa_agent_get_info(agent, HSA_AGENT_INFO_QUEUE_MAX_SIZE, &TmpUInt),
614+
"Error returned from hsa_agent_get_info when obtaining "
615+
"HSA_AGENT_INFO_QUEUE_MAX_SIZE\n");
616+
printf(" Queue Max Size: \t\t\t%u \n", TmpUInt);
617+
618+
// Getting cache information
619+
printf(" Cache:\n");
620+
621+
// FIXME: This is deprecated according to HSA documentation. But using
622+
// hsa_agent_iterate_caches and hsa_cache_get_info breaks execution during
623+
// runtime.
624+
core::checkResult(
625+
hsa_agent_get_info(agent, HSA_AGENT_INFO_CACHE_SIZE, CacheSize),
626+
"Error returned from hsa_agent_get_info when obtaining "
627+
"HSA_AGENT_INFO_CACHE_SIZE\n");
628+
629+
for (int i = 0; i < 4; i++) {
630+
if (CacheSize[i]) {
631+
printf(" L%u: \t\t\t\t%u bytes\n", i, CacheSize[i]);
632+
}
633+
}
634+
635+
core::checkResult(
636+
hsa_agent_get_info(agent,
637+
(hsa_agent_info_t)HSA_AMD_AGENT_INFO_CACHELINE_SIZE,
638+
&TmpUInt),
639+
"Error returned from hsa_agent_get_info when obtaining "
640+
"HSA_AMD_AGENT_INFO_CACHELINE_SIZE\n");
641+
printf(" Cacheline Size: \t\t\t%u \n", TmpUInt);
642+
core::checkResult(
643+
hsa_agent_get_info(
644+
agent, (hsa_agent_info_t)HSA_AMD_AGENT_INFO_MAX_CLOCK_FREQUENCY,
645+
&TmpUInt),
646+
"Error returned from hsa_agent_get_info when obtaining "
647+
"HSA_AMD_AGENT_INFO_MAX_CLOCK_FREQUENCY\n");
648+
printf(" Max Clock Freq(MHz): \t\t%u \n", TmpUInt);
649+
core::checkResult(
650+
hsa_agent_get_info(
651+
agent, (hsa_agent_info_t)HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT,
652+
&TmpUInt),
653+
"Error returned from hsa_agent_get_info when obtaining "
654+
"HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT\n");
655+
printf(" Compute Units: \t\t\t%u \n", TmpUInt);
656+
core::checkResult(hsa_agent_get_info(
657+
agent,
658+
(hsa_agent_info_t)HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU,
659+
&TmpUInt),
660+
"Error returned from hsa_agent_get_info when obtaining "
661+
"HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU\n");
662+
printf(" SIMD per CU: \t\t\t%u \n", TmpUInt);
663+
core::checkResult(
664+
hsa_agent_get_info(agent, HSA_AGENT_INFO_FAST_F16_OPERATION, &TmpBool),
665+
"Error returned from hsa_agent_get_info when obtaining "
666+
"HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU\n");
667+
printf(" Fast F16 Operation: \t\t%s \n", (TmpBool ? "TRUE" : "FALSE"));
668+
core::checkResult(
669+
hsa_agent_get_info(agent, HSA_AGENT_INFO_WAVEFRONT_SIZE, &TmpUInt2),
670+
"Error returned from hsa_agent_get_info when obtaining "
671+
"HSA_AGENT_INFO_WAVEFRONT_SIZE\n");
672+
printf(" Wavefront Size: \t\t\t%u \n", TmpUInt2);
673+
core::checkResult(
674+
hsa_agent_get_info(agent, HSA_AGENT_INFO_WORKGROUP_MAX_SIZE, &TmpUInt),
675+
"Error returned from hsa_agent_get_info when obtaining "
676+
"HSA_AGENT_INFO_WORKGROUP_MAX_SIZE\n");
677+
printf(" Workgroup Max Size: \t\t%u \n", TmpUInt);
678+
core::checkResult(hsa_agent_get_info(agent,
679+
HSA_AGENT_INFO_WORKGROUP_MAX_DIM,
680+
workgroupMaxDim),
681+
"Error returned from hsa_agent_get_info when obtaining "
682+
"HSA_AGENT_INFO_WORKGROUP_MAX_DIM\n");
683+
printf(" Workgroup Max Size per Dimension:\n");
684+
printf(" x: \t\t\t\t%u\n", workgroupMaxDim[0]);
685+
printf(" y: \t\t\t\t%u\n", workgroupMaxDim[1]);
686+
printf(" z: \t\t\t\t%u\n", workgroupMaxDim[2]);
687+
core::checkResult(hsa_agent_get_info(
688+
agent,
689+
(hsa_agent_info_t)HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU,
690+
&TmpUInt),
691+
"Error returned from hsa_agent_get_info when obtaining "
692+
"HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU\n");
693+
printf(" Max Waves Per CU: \t\t\t%u \n", TmpUInt);
694+
printf(" Max Work-item Per CU: \t\t%u \n", TmpUInt * TmpUInt2);
695+
core::checkResult(
696+
hsa_agent_get_info(agent, HSA_AGENT_INFO_GRID_MAX_SIZE, &TmpUInt),
697+
"Error returned from hsa_agent_get_info when obtaining "
698+
"HSA_AGENT_INFO_GRID_MAX_SIZE\n");
699+
printf(" Grid Max Size: \t\t\t%u \n", TmpUInt);
700+
core::checkResult(
701+
hsa_agent_get_info(agent, HSA_AGENT_INFO_GRID_MAX_DIM, &gridMaxDim),
702+
"Error returned from hsa_agent_get_info when obtaining "
703+
"HSA_AGENT_INFO_GRID_MAX_DIM\n");
704+
printf(" Grid Max Size per Dimension: \t\t\n");
705+
printf(" x: \t\t\t\t%u\n", gridMaxDim.x);
706+
printf(" y: \t\t\t\t%u\n", gridMaxDim.y);
707+
printf(" z: \t\t\t\t%u\n", gridMaxDim.z);
708+
core::checkResult(
709+
hsa_agent_get_info(agent, HSA_AGENT_INFO_FBARRIER_MAX_SIZE, &TmpUInt),
710+
"Error returned from hsa_agent_get_info when obtaining "
711+
"HSA_AGENT_INFO_FBARRIER_MAX_SIZE\n");
712+
printf(" Max fbarriers/Workgrp: \t\t%u\n", TmpUInt);
713+
714+
printf(" Memory Pools:\n");
715+
auto CB_mem = [](hsa_amd_memory_pool_t region, void *data) -> hsa_status_t {
716+
std::string TmpStr;
717+
size_t size;
718+
bool alloc, access;
719+
hsa_amd_segment_t segment;
720+
hsa_amd_memory_pool_global_flag_t globalFlags;
721+
core::checkResult(
722+
hsa_amd_memory_pool_get_info(
723+
region, HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS, &globalFlags),
724+
"Error returned from hsa_amd_memory_pool_get_info when obtaining "
725+
"HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS\n");
726+
core::checkResult(hsa_amd_memory_pool_get_info(
727+
region, HSA_AMD_MEMORY_POOL_INFO_SEGMENT, &segment),
728+
"Error returned from hsa_amd_memory_pool_get_info when "
729+
"obtaining HSA_AMD_MEMORY_POOL_INFO_SEGMENT\n");
730+
731+
switch (segment) {
732+
case HSA_AMD_SEGMENT_GLOBAL:
733+
TmpStr = "GLOBAL; FLAGS: ";
734+
if (HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT & globalFlags)
735+
TmpStr += "KERNARG, ";
736+
if (HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_FINE_GRAINED & globalFlags)
737+
TmpStr += "FINE GRAINED, ";
738+
if (HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_COARSE_GRAINED & globalFlags)
739+
TmpStr += "COARSE GRAINED, ";
740+
break;
741+
case HSA_AMD_SEGMENT_READONLY:
742+
TmpStr = "READONLY";
743+
break;
744+
case HSA_AMD_SEGMENT_PRIVATE:
745+
TmpStr = "PRIVATE";
746+
break;
747+
case HSA_AMD_SEGMENT_GROUP:
748+
TmpStr = "GROUP";
749+
break;
750+
}
751+
printf(" Pool %s: \n", TmpStr.c_str());
752+
753+
core::checkResult(hsa_amd_memory_pool_get_info(
754+
region, HSA_AMD_MEMORY_POOL_INFO_SIZE, &size),
755+
"Error returned from hsa_amd_memory_pool_get_info when "
756+
"obtaining HSA_AMD_MEMORY_POOL_INFO_SIZE\n");
757+
printf(" Size: \t\t\t\t %zu bytes\n", size);
758+
core::checkResult(
759+
hsa_amd_memory_pool_get_info(
760+
region, HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED, &alloc),
761+
"Error returned from hsa_amd_memory_pool_get_info when obtaining "
762+
"HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED\n");
763+
printf(" Allocatable: \t\t\t %s\n", (alloc ? "TRUE" : "FALSE"));
764+
core::checkResult(
765+
hsa_amd_memory_pool_get_info(
766+
region, HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_GRANULE, &size),
767+
"Error returned from hsa_amd_memory_pool_get_info when obtaining "
768+
"HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_GRANULE\n");
769+
printf(" Runtime Alloc Granule: \t\t %zu bytes\n", size);
770+
core::checkResult(
771+
hsa_amd_memory_pool_get_info(
772+
region, HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALIGNMENT, &size),
773+
"Error returned from hsa_amd_memory_pool_get_info when obtaining "
774+
"HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALIGNMENT\n");
775+
printf(" Runtime Alloc alignment: \t %zu bytes\n", size);
776+
core::checkResult(
777+
hsa_amd_memory_pool_get_info(
778+
region, HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL, &access),
779+
"Error returned from hsa_amd_memory_pool_get_info when obtaining "
780+
"HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL\n");
781+
printf(" Accessable by all: \t\t %s\n",
782+
(access ? "TRUE" : "FALSE"));
783+
784+
return HSA_STATUS_SUCCESS;
785+
};
786+
// Iterate over all the memory regions for this agent. Get the memory region
787+
// type and size
788+
hsa_amd_agent_iterate_memory_pools(agent, CB_mem, nullptr);
789+
790+
printf(" ISAs:\n");
791+
auto CB_isas = [](hsa_isa_t isa, void *data) -> hsa_status_t {
792+
char TmpChar[1000];
793+
core::checkResult(hsa_isa_get_info_alt(isa, HSA_ISA_INFO_NAME, TmpChar),
794+
"Error returned from hsa_isa_get_info_alt when "
795+
"obtaining HSA_ISA_INFO_NAME\n");
796+
printf(" Name: \t\t\t\t %s\n", TmpChar);
797+
798+
return HSA_STATUS_SUCCESS;
799+
};
800+
// Iterate over all the memory regions for this agent. Get the memory region
801+
// type and size
802+
hsa_agent_iterate_isas(agent, CB_isas, nullptr);
803+
}
804+
545805
// Record entry point associated with device
546806
void addOffloadEntry(int32_t device_id, __tgt_offload_entry entry) {
547807
assert(device_id < (int32_t)FuncGblEntries.size() &&
@@ -2338,4 +2598,12 @@ int32_t __tgt_rtl_synchronize(int32_t device_id, __tgt_async_info *AsyncInfo) {
23382598
}
23392599
return OFFLOAD_SUCCESS;
23402600
}
2601+
2602+
void __tgt_rtl_print_device_info(int32_t device_id) {
2603+
// TODO: Assertion to see if device_id is correct
2604+
// NOTE: We don't need to set context for print device info.
2605+
2606+
DeviceInfo.printDeviceInfo(device_id, DeviceInfo.HSAAgents[device_id]);
2607+
}
2608+
23412609
} // extern "C"

0 commit comments

Comments
 (0)