@@ -282,6 +282,16 @@ static void callbackQueue(hsa_status_t status, hsa_queue_t *source,
282
282
283
283
namespace core {
284
284
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
+
285
295
void packet_store_release (uint32_t *packet, uint16_t header, uint16_t rest) {
286
296
__atomic_store_n (packet, header | (rest << 16 ), __ATOMIC_RELEASE);
287
297
}
@@ -542,6 +552,256 @@ class RTLDeviceInfoTy : HSALifetime {
542
552
return freesignalpool_memcpy (dest, src, size, impl_memcpy_h2d, deviceId);
543
553
}
544
554
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
+
545
805
// Record entry point associated with device
546
806
void addOffloadEntry (int32_t device_id, __tgt_offload_entry entry) {
547
807
assert (device_id < (int32_t )FuncGblEntries.size () &&
@@ -2338,4 +2598,12 @@ int32_t __tgt_rtl_synchronize(int32_t device_id, __tgt_async_info *AsyncInfo) {
2338
2598
}
2339
2599
return OFFLOAD_SUCCESS;
2340
2600
}
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
+
2341
2609
} // extern "C"
0 commit comments