/
rocm_smi_device.go
2049 lines (1883 loc) · 87.4 KB
/
rocm_smi_device.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2019 RRZE, University Erlangen-Nuremberg
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package rocm_smi
//import "fmt"
//import "strings"
const defaultRsmiStringLength uint32 = 1000
var ctoGoFuncMapping = map[string]string {
"rsmi_dev_fan_reset": "DeviceResetFan",
"rsmi_dev_fan_speed_set": "DeviceSetFanSpeed",
"rsmi_dev_volt_metric_get": "DeviceGetVoltageMetric",
"rsmi_dev_temp_metric_get": "DeviceGetTemperatureMetric",
"rsmi_dev_busy_percent_get": "DeviceGetBusyPercent",
"rsmi_utilization_count_get": "DeviceGetUtilizationCounters",
"rsmi_dev_fan_speed_max_get": "DeviceGetMaxFanSpeed",
"rsmi_dev_fan_speed_get": "DeviceGetFanSpeed",
"rsmi_dev_fan_rpms_get": "DeviceGetFanRpms",
"rsmi_dev_memory_reserved_pages_get": "DeviceGetMemoryReservedPages",
"rsmi_dev_memory_busy_percent_get": "DeviceGetMemoryUtilization",
"rsmi_dev_memory_usage_get": "DeviceGetUsedMemory",
"rsmi_dev_memory_total_get": "DeviceGetTotalMemory",
"rsmi_dev_power_profile_set": "DeviceSetPowerProfile",
"rsmi_dev_power_cap_set": "DeviceSetPowerCap",
"rsmi_dev_energy_count_get": "DeviceGetEnergyCount",
"rsmi_dev_power_cap_range_get": "DeviceGetPowerCapRange",
"rsmi_dev_power_cap_default_get": "DeviceGetDefaultPowerCap",
"rsmi_dev_power_cap_get": "DeviceGetPowerCap",
"rsmi_dev_power_ave_get": "DeviceGetPowerAverage",
"rsmi_topo_numa_affinity_get": "DeviceGetNumaAffinity",
"rsmi_dev_pci_replay_counter_get": "DeviceGetPciReplayCounter",
"rsmi_dev_pci_throughput_get": "DeviceGetPciThroughput",
"rsmi_dev_pci_bandwidth_set": "DeviceSetPciBandwidth",
"rsmi_dev_pci_bandwidth_get": "DeviceGetPciBandwidth",
"rsmi_dev_pci_id_get": "DeviceGetPciId",
"rsmi_dev_unique_id_get": "DeviceGetUniqueId",
"rsmi_dev_drm_render_minor_get": "DeviceGetDrmRenderMinor",
"rsmi_dev_subsystem_id_get": "DeviceGetSubsystemId",
"rsmi_dev_subsystem_name_get": "DeviceGetSubsystemName",
"rsmi_dev_serial_number_get": "DeviceGetSerial",
"rsmi_dev_vram_vendor_get": "DeviceGetVramVendor",
"rsmi_dev_vendor_id_get": "DeviceGetVendorId",
"rsmi_dev_vendor_name_get": "DeviceGetVendorName",
"rsmi_dev_sku_get": "DeviceGetSku",
"rsmi_dev_name_get": "DeviceGetName",
"rsmi_dev_brand_get": "DeviceGetBrand",
"rsmi_dev_perf_level_get": "DeviceGetPerfLevel",
"rsmi_perf_determinism_mode_set": "DeviceSetDeterminismMode",
"rsmi_dev_overdrive_level_get": "DeviceGetOverdriveLevel",
"rsmi_dev_gpu_clk_freq_get": "DeviceGetClockFrequency",
"rsmi_dev_od_volt_info_get": "DeviceGetVoltageFrequencyCurve",
"rsmi_dev_gpu_metrics_info_get": "DeviceGetMetrics",
"rsmi_dev_clk_range_set": "DeviceSetClockRange",
"rsmi_dev_od_clk_info_set": "DeviceSetClockInfo",
"rsmi_dev_od_volt_info_set": "DeviceSetVoltageInfo",
"rsmi_dev_od_volt_curve_regions_get": "DeviceGetVoltageFrequencyCurveRegions",
"rsmi_dev_power_profile_presets_get": "DeviceGetPowerProfile",
"rsmi_dev_perf_level_set": "DeviceSetPerfLevel_v2",
"rsmi_dev_perf_level_set_v1": "DeviceSetPerfLevel_v1",
"rsmi_dev_vbios_version_get": "DeviceGetVbiosVersionString",
"rsmi_dev_firmware_version_get": "DeviceGetFirmwareVersion",
"rsmi_dev_overdrive_level_set_v1": "DeviceSetOverdriveLevel_v1",
"rsmi_dev_overdrive_level_set": "DeviceSetOverdriveLevel_v2",
"rsmi_dev_gpu_clk_freq_set": "DeviceSetClockFrequency",
"rsmi_dev_ecc_count_get": "DeviceGetEccCount",
"rsmi_dev_ecc_status_get": "DeviceGetEccStatus",
"rsmi_dev_ecc_enabled_get": "DeviceGetEccMask",
"rsmi_dev_xgmi_error_status": "DeviceXgmiErrorStatus",
"rsmi_dev_xgmi_error_reset": "DeviceXgmiErrorReset",
"rsmi_dev_xgmi_hive_id_get": "DeviceXgmiHiveId",
"rsmi_topo_get_numa_node_number": "DeviceGetNumaNode",
"rsmi_topo_get_link_weight": "DeviceGetLinkWeight",
"rsmi_minmax_bandwidth_get": "DeviceGetMinMaxBandwidth",
"rsmi_topo_get_link_type": "DeviceGetLinkType",
"rsmi_is_P2P_accessible": "DeviceIsP2PAccessible",
"rsmi_event_notification_init": "DeviceInitEventNotification",
"rsmi_event_notification_mask_set": "DeviceSetEventNotificationMask",
"rsmi_event_notification_get": "GetEventNotification",
"rsmi_event_notification_stop": "DeviceStopEventNotification",
"rsmi_dev_counter_group_supported": "DeviceCounterGroupSupported",
"rsmi_counter_available_counters_get": "DeviceCounterGetAvailable",
"rsmi_dev_counter_create": "DeviceCounterCreate",
"rsmi_counter_control": "CounterControl",
"rsmi_counter_read": "CounterRead",
"rsmi_dev_counter_destroy": "CounterDestroy",
"rsmi_compute_process_info_get": "ComputeProcesses",
"rsmi_compute_process_info_by_pid_get": "ComputeProcessByPid",
"rsmi_compute_process_gpus_get": "ComputeProcessGpus",
}
func bytes2String(bytes []byte) string {
s := make([]byte, 0)
for _, v := range bytes {
s = append(s, v)
}
return string(s)
}
// NumMonitorDevices gets the number of devices that have monitor information.
// The number of devices which have monitors is returned. Monitors are
// referenced by the index which can be between 0 and the returned num_devices - 1.
//
// Returns STATUS_SUCCESS upon successful call.
func NumMonitorDevices() (int, RSMI_status) {
var DeviceCount uint32
ret := rsmi_num_monitor_devices(&DeviceCount)
return int(DeviceCount), ret
}
// DeviceGetHandleByIndex gets the device handle associated with the device with provided device index.
// It also reads the supported functions and their supported arguments. It retrieves also the **not** unique ID.
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
func DeviceGetHandleByIndex(Index int) (DeviceHandle, RSMI_status) {
var index uint32 = uint32(Index)
handle := DeviceHandle{
handle: 0,
index: index,
supported: nil,
}
ret := rsmi_dev_id_get(handle.index, &handle.handle)
if ret == STATUS_SUCCESS {
B2S := func(bs [200]int8) string {
b := make([]byte, 0)
for _, v := range bs {
if v == 0 {
break
}
b = append(b, byte(v))
}
return string(b)
}
var funcs RSMI_helper_function
ret = rsmi_helper_func_variants_get(handle.index, &funcs)
if ret == STATUS_SUCCESS {
handle.supported = make(map[string]map[uint64][]uint64)
for f := 0; f < int(funcs.Functions); f++ {
name := B2S(funcs.Functionlist[f].Name)
handle.supported[name] = make(map[uint64][]uint64)
for s := 0; s < int(funcs.Functionlist[f].Sensors); s++ {
sdata := funcs.Functionlist[f].Sensorlist[s]
sensor := uint64(sdata.Variant_id)
l := make([]uint64, 0)
for v := 0; v < int(sdata.Num_variants); v++ {
l = append(l, uint64(sdata.Variantlist[v]))
}
handle.supported[name][sensor] = l
}
if goname, ok := ctoGoFuncMapping[name]; ok {
handle.supported[goname] = handle.supported[name]
}
}
}
}
return handle, ret
}
// DeviceGetBrand gets the brand string of a gpu device.
// If the sku associated with the device is not found as one of the values
// contained within rsmi_dev_brand_get, then this function will return the
// device marketing name as a string instead of the brand name.
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
// Returns STATUS_INSUFFICIENT_SIZE when the vendor name is longer than defaultRsmiStringLength characters.
func DeviceGetBrand(Device DeviceHandle) (string, RSMI_status) {
if _, ok := Device.supported["rsmi_dev_brand_get"]; !ok {
return "", STATUS_NOT_SUPPORTED
}
var brand []byte = make([]byte, defaultRsmiStringLength)
bptr := &brand[0]
ret := rsmi_dev_brand_get(Device.index, bptr, defaultRsmiStringLength)
return bytes2String(brand), ret
}
// DeviceGetBrand gets the brand string of a gpu device.
// If the sku associated with the device is not found as one of the values
// contained within rsmi_dev_brand_get, then this function will return the
// device marketing name as a string instead of the brand name.
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
// Returns STATUS_INSUFFICIENT_SIZE when the vendor name is longer than defaultRsmiStringLength characters.
func (Device DeviceHandle) GetBrand() (string, RSMI_status) {
return DeviceGetBrand(Device)
}
// DeviceGetName gets the name string of a gpu device.
// If the integer ID associated with the device is not found in one of the system
// files containing device name information (e.g. /usr/share/misc/pci.ids), then this
// function will return the hex device ID as a string.
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
// Returns STATUS_INSUFFICIENT_SIZE when the vendor name is longer than defaultRsmiStringLength characters.
func DeviceGetName(Device DeviceHandle) (string, RSMI_status) {
if _, ok := Device.supported["rsmi_dev_name_get"]; !ok {
return "", STATUS_NOT_SUPPORTED
}
var name []byte = make([]byte, defaultRsmiStringLength)
nptr := &name[0]
ret := rsmi_dev_name_get(Device.index, nptr, defaultRsmiStringLength)
return bytes2String(name), ret
}
// GetName gets the name string of a gpu device.
// If the integer ID associated with the device is not found in one of the system
// files containing device name information (e.g. /usr/share/misc/pci.ids), then this
// function will return the hex device ID as a string.
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
// Returns STATUS_INSUFFICIENT_SIZE when the vendor name is longer than defaultRsmiStringLength characters.
func (Device DeviceHandle) GetName() (string, RSMI_status) {
return DeviceGetName(Device)
}
// DeviceGetSku gets the SKU for a device.
// This function will attempt to obtain the SKU from the Product Information FRU chip, present on server ASICs
//
// Note: There are versions of the rocm_smi library which do not export the function rsmi_dev_sku_get. Therefore the bindings
// perform a symbol lookup at initialization. If it is not available, the deviceGetSkuFake function is assigned to DeviceGetSku
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
var DeviceGetSku = deviceGetSkuFake
// DeviceGetSkuReal is the actual reading function for the SKU. But it is not supported by some devices.
func deviceGetSkuReal(Device DeviceHandle) (string, RSMI_status) {
var Sku []byte = make([]byte, defaultRsmiStringLength)
var ret RSMI_status = STATUS_NOT_SUPPORTED
if _, ok := Device.supported["rsmi_dev_sku_get"]; !ok {
sptr := &Sku[0]
ret = rsmi_dev_sku_get(Device.index, sptr)
}
return bytes2String(Sku), ret
}
// DeviceGetSkuReal is returning 'NA' as SKU because the funtion is not supported by the device
func deviceGetSkuFake(Device DeviceHandle) (string, RSMI_status) {
return "NA", STATUS_NOT_SUPPORTED
}
// GetSku gets the SKU for a device..
// This function will attempt to obtain the SKU from the Product Information FRU chip, present on server ASICs
//
// Note: There are versions of the rocm_smi library which do not export the function rsmi_dev_sku_get. Therefore the bindings
// perform a symbol lookup at initialization. If it is not available, the deviceGetSkuFake function is assigned to DeviceGetSku
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
func (Device DeviceHandle) GetSku() (string, RSMI_status) {
return DeviceGetSku(Device)
}
// DeviceGetVendorName gets the name string for a give vendor ID.
// If the integer ID associated with the vendor is not found in one of
// the system files containing device name information (e.g. /usr/share/misc/pci.ids),
// then this function will return the hex vendor ID as a string.
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
// Returns STATUS_INSUFFICIENT_SIZE when the vendor name is longer than defaultRsmiStringLength characters.
func DeviceGetVendorName(Device DeviceHandle) (string, RSMI_status) {
if _, ok := Device.supported["rsmi_dev_vendor_name_get"]; !ok {
return "", STATUS_NOT_SUPPORTED
}
var Name []byte = make([]byte, defaultRsmiStringLength)
nptr := &Name[0]
ret := rsmi_dev_vendor_name_get(Device.index, nptr, defaultRsmiStringLength)
return bytes2String(Name), ret
}
// GetVendorName gets the name string for a give vendor ID.
// If the integer ID associated with the vendor is not found in one of
// the system files containing device name information (e.g. /usr/share/misc/pci.ids),
// then this function will return the hex vendor ID as a string.
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
// Returns STATUS_INSUFFICIENT_SIZE when the vendor name is longer than defaultRsmiStringLength characters.
func (Device DeviceHandle) GetVendorName() (string, RSMI_status) {
return DeviceGetVendorName(Device)
}
// DeviceGetVendorId gets the device vendor id associated with the device
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
func DeviceGetVendorId(Device DeviceHandle) (uint16, RSMI_status) {
var id uint16 = 0
if _, ok := Device.supported["rsmi_dev_vendor_id_get"]; !ok {
return id, STATUS_NOT_SUPPORTED
}
ret := rsmi_dev_vendor_id_get(Device.index, &id)
return id, ret
}
// GetVendorId gets the device vendor id associated with the device
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_NOT_SUPPORTED when installed software or hardware does not support this function with the given arguments.
// Returns STATUS_INVALID_ARGS when the provided arguments are not valid.
func (Device DeviceHandle) GetVendorId() (uint16, RSMI_status) {
return DeviceGetVendorId(Device)
}
// DeviceGetVramVendor gets the vram vendor string of a gpu device.
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_INSUFFICIENT_SIZE when the vram vendor name is longer than defaultRsmiStringLength characters.
func DeviceGetVramVendor(Device DeviceHandle) (string, RSMI_status) {
if _, ok := Device.supported["rsmi_dev_vram_vendor_get"]; !ok {
return "", STATUS_NOT_SUPPORTED
}
var Name []byte = make([]byte, defaultRsmiStringLength)
nptr := &Name[0]
ret := rsmi_dev_vram_vendor_get(Device.index, nptr, defaultRsmiStringLength)
return bytes2String(Name), ret
}
// GetVramVendor gets the vram vendor string of a gpu device.
//
// Returns STATUS_SUCCESS when call was successful.
// Returns STATUS_INSUFFICIENT_SIZE when the vram vendor name is longer than defaultRsmiStringLength characters.
func (Device DeviceHandle) GetVramVendor() (string, RSMI_status) {
return DeviceGetVramVendor(Device)
}
// DeviceGetSerial gets the serial number string for a device
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
// STATUS_INSUFFICIENT_SIZE is returned if version string is larger than defaultRsmiStringLength bytes.
func DeviceGetSerialNumber(Device DeviceHandle) (string, RSMI_status) {
if _, ok := Device.supported["rsmi_dev_serial_number_get"]; !ok {
return "", STATUS_NOT_SUPPORTED
}
var size uint32 = 100
var tmp []byte
var ret RSMI_status = STATUS_SUCCESS
for size = 100; size < defaultRsmiStringLength; size += 100 {
tmp = make([]byte, size)
sptr := &tmp[0]
ret = rsmi_dev_serial_number_get(Device.index, sptr, size)
}
Serial := make([]byte, 0)
for _, v := range tmp {
if v != 0 {
Serial = append(Serial, v)
}
}
return bytes2String(Serial), ret
}
// GetSerialNumber gets the serial number string for a device
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
// STATUS_INSUFFICIENT_SIZE is returned if version string is larger than defaultRsmiStringLength bytes.
func (Device DeviceHandle) GetSerialNumber() (string, RSMI_status) {
return DeviceGetSerialNumber(Device)
}
// DeviceGetSubsystemName gets the name string for the device subsytem
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
// STATUS_INSUFFICIENT_SIZE is returned if version string is larger than defaultRsmiStringLength bytes.
func DeviceGetSubsystemName(Device DeviceHandle) (string, RSMI_status) {
if _, ok := Device.supported["rsmi_dev_subsystem_name_get"]; !ok {
return "", STATUS_NOT_SUPPORTED
}
var Name []byte = make([]byte, defaultRsmiStringLength)
nptr := &Name[0]
ret := rsmi_dev_subsystem_name_get(Device.index, nptr, defaultRsmiStringLength)
return bytes2String(Name), ret
}
// GetSubsystemName gets the name string for the device subsytem
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
// STATUS_INSUFFICIENT_SIZE is returned if version string is larger than defaultRsmiStringLength bytes.
func (Device DeviceHandle) GetSubsystemName() (string, RSMI_status) {
return DeviceGetSubsystemName(Device)
}
// DeviceGetSubsystemId gets the subsystem device id associated with the device
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetSubsystemId(Device DeviceHandle) (uint16, RSMI_status) {
var id uint16 = 0
if _, ok := Device.supported["rsmi_dev_subsystem_id_get"]; !ok {
return id, STATUS_NOT_SUPPORTED
}
ret := rsmi_dev_subsystem_id_get(Device.index, &id)
return id, ret
}
// DeviceGetSubsystemId gets the subsystem device id associated with the device
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetSubsystemId() (uint16, RSMI_status) {
return DeviceGetSubsystemId(Device)
}
// DeviceGetDrmRenderMinor gets the drm minor number associated with the device
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetDrmRenderMinor(Device DeviceHandle) (uint32, RSMI_status) {
var minor uint32 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if _, ok := Device.supported["rsmi_dev_drm_render_minor_get"]; ok {
ret = rsmi_dev_drm_render_minor_get(Device.index, &minor)
}
return minor, ret
}
// DeviceGetDrmRenderMinor gets the drm minor number associated with the device
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetDrmRenverMinor() (uint32, RSMI_status) {
return DeviceGetDrmRenderMinor(Device)
}
// DeviceGetUniqueId gets Unique ID
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetUniqueId(Device DeviceHandle) (uint64, RSMI_status) {
var id uint64 = 0
if _, ok := Device.supported["rsmi_dev_unique_id_get"]; !ok {
return id, STATUS_NOT_SUPPORTED
}
ret := rsmi_dev_unique_id_get(Device.index, &id)
return id, ret
}
// DeviceGetUniqueId gets Unique ID
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetUniqueId() (uint64, RSMI_status) {
return DeviceGetUniqueId(Device)
}
// DeviceGetPciId gets the unique PCI device identifier associated with the device
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetPciId(Device DeviceHandle) (uint64, RSMI_status) {
var id uint64 = 0
if _, ok := Device.supported["rsmi_dev_pci_id_get"]; !ok {
return id, STATUS_NOT_SUPPORTED
}
ret := rsmi_dev_pci_id_get(Device.index, &id)
return id, ret
}
// DeviceGetPciId gets the unique PCI device identifier associated with the device
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetPciId() (uint64, RSMI_status) {
return DeviceGetPciId(Device)
}
type Pci_info struct {
Domain uint32 // PCI domain
Bus uint8 // PCI bus
Device uint8 // PCI device
Function uint8 // PCI function
}
// DeviceGetPciInfo gets the unique PCI device identifier associated with the device split into its parts: PCI domain, PCI bus, PCI device and function.
//
// Note: This is an own addition to simply usage, it uses DeviceGetPciId to retrieve the actual PCI identifer and splits it into the parts.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetPciInfo(Device DeviceHandle) (Pci_info, RSMI_status) {
var id uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
info := Pci_info{
Domain: 0,
Bus: 0,
Device: 0,
Function: 0,
}
id, ret = DeviceGetPciId(Device)
if ret == STATUS_SUCCESS {
info.Domain = uint32((id >> 32) & 0xffffffff)
info.Bus = uint8((id >> 8) & 0xff)
info.Device = uint8((id >> 3) & 0x1f)
info.Function = uint8(id & 0x7)
}
return info, ret
}
// GetPciInfo gets the unique PCI device identifier associated with the device split into its parts: PCI domain, PCI bus, PCI device and function.
//
// Note: This is an own addition to simply usage, it uses DeviceGetPciId to retrieve the actual PCI identifer and splits it into the parts.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetPciInfo() (Pci_info, RSMI_status) {
return DeviceGetPciInfo(Device)
}
// DeviceGetPciBandwidth gets the list of possible PCIe bandwidths that are available.
//
// STATUS_SUCCESS call was successful.
func DeviceGetPciBandwidth(Device DeviceHandle) (RSMI_pcie_bandwidth, RSMI_status) {
var info RSMI_pcie_bandwidth = RSMI_pcie_bandwidth {
Rate : RSMI_frequencies {
Supported: 0,
Current: 0,
},
}
if _, ok := Device.supported["rsmi_dev_pci_bandwidth_get"]; !ok {
return info, STATUS_NOT_SUPPORTED
}
ret := rsmi_dev_pci_bandwidth_get(Device.index, &info)
return info, ret
}
// GetPciBandwidth gets the list of possible PCIe bandwidths that are available.
//
// STATUS_SUCCESS call was successful.
func (Device DeviceHandle) GetPciBandwidth() (RSMI_pcie_bandwidth, RSMI_status) {
return DeviceGetPciBandwidth(Device)
}
// DeviceSetPciBandwidth controls the set of allowed PCIe bandwidths that can be used.
//
// STATUS_SUCCESS call was successful.
// STATUS_PERMISSION function requires root access.
func DeviceSetPciBandwidth(Device DeviceHandle, Mask uint64) RSMI_status {
ret := STATUS_NOT_SUPPORTED
if _, ok := Device.supported["rsmi_dev_pci_bandwidth_set"]; ok {
ret = rsmi_dev_pci_bandwidth_set(Device.index, Mask)
}
return ret
}
// SetPciBandwidth controls the set of allowed PCIe bandwidths that can be used.
//
// STATUS_SUCCESS call was successful.
// STATUS_PERMISSION function requires root access.
func (Device DeviceHandle) SetPciBandwidth(Mask uint64) RSMI_status {
return DeviceSetPciBandwidth(Device, Mask)
}
// DeviceGetPciThroughput gets PCIe traffic information for the device.
// This function returns the number of bytes sent and received in 1 second and the maximum possible packet size.
//
// Note: The function blocks execution for 1 second.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
func DeviceGetPciThroughput(Device DeviceHandle) (uint64, uint64, uint64, RSMI_status) {
var sent uint64 = 0
var recv uint64 = 0
var max_pkts_size uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if _, ok := Device.supported["rsmi_dev_pci_throughput_get"]; ok {
ret = rsmi_dev_pci_throughput_get(Device.index, &sent, &recv, &max_pkts_size)
}
return sent, recv, max_pkts_size, ret
}
// GetPciThroughput gets PCIe traffic information for the device.
// This function returns the number of bytes sent and received in 1 second and the maximum possible packet size.
//
// Note: The function blocks execution for 1 second.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
func (Device DeviceHandle) GetPciThroughput() (uint64, uint64, uint64, RSMI_status) {
return DeviceGetPciThroughput(Device)
}
// DeviceGetPciReplayCounter gets the PCIe replay counter.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetPciReplayCounter(Device DeviceHandle) (uint64, RSMI_status) {
var counter uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if _, ok := Device.supported["rsmi_dev_pci_replay_counter_get"]; ok {
ret = rsmi_dev_pci_replay_counter_get(Device.index, &counter)
}
return counter, ret
}
// GetPciReplayCounter gets the PCIe replay counter.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetPciReplayCounter() (uint64, RSMI_status) {
return DeviceGetPciReplayCounter(Device)
}
// DeviceGetNumaAffinity gets the NUMA node associated with a device.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetNumaAffinity(Device DeviceHandle) (uint32, RSMI_status) {
var id uint32 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if _, ok := Device.supported["rsmi_topo_numa_affinity_get"]; ok {
ret = rsmi_topo_numa_affinity_get(Device.index, &id)
}
return id, ret
}
// GetNumaAffinity gets the NUMA node associated with a device.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetNumaAffinity() (uint32, RSMI_status) {
return DeviceGetNumaAffinity(Device)
}
// DeviceGetPowerAverage gets the average power consumption of the device.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetPowerAverage(Device DeviceHandle, Sensor uint32) (uint64, RSMI_status) {
var power uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if sensors, ok := Device.supported["rsmi_dev_power_ave_get"]; ok {
if _, ok := sensors[uint64(Sensor)]; ok {
ret = rsmi_dev_power_ave_get(Device.index, Sensor, &power)
} else if defaults, ok := sensors[DEFAULT_VARIANT]; ok {
if len(defaults) > 0 {
ret = rsmi_dev_power_ave_get(Device.index, uint32(defaults[0]), &power)
}
}
}
return power, ret
}
// GetPowerAverage gets the average power consumption of the device.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetPowerAverage(Sensor uint32) (uint64, RSMI_status) {
return DeviceGetPowerAverage(Device, Sensor)
}
// DeviceGetPowerCap gets the cap on power which, when reached, causes the system to take action to reduce power.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetPowerCap(Device DeviceHandle, Sensor uint32) (uint64, RSMI_status) {
var power uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if sensors, ok := Device.supported["rsmi_dev_power_cap_get"]; ok {
if _, ok := sensors[uint64(Sensor)]; ok {
ret = rsmi_dev_power_cap_get(Device.index, Sensor, &power)
} else if defaults, ok := sensors[DEFAULT_VARIANT]; ok {
if len(defaults) > 0 {
ret = rsmi_dev_power_cap_get(Device.index, uint32(defaults[0]), &power)
}
}
}
return power, ret
}
// GetPowerCap gets the cap on power which, when reached, causes the system to take action to reduce power.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetPowerCap(Sensor uint32) (uint64, RSMI_status) {
return DeviceGetPowerCap(Device, Sensor)
}
// DeviceGetDefaultPowerCap gets the default power cap for the device.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetDefaultPowerCap(Device DeviceHandle) (uint64, RSMI_status) {
var power uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
// if sensors, ok := Device.supported["rsmi_dev_power_cap_default_get"]; ok {
// if _, ok := sensors[uint64(Sensor)]; ok {
// ret = rsmi_dev_power_cap_default_get(Device.index, &power)
// } else if defaults, ok := sensors[DEFAULT_VARIANT]; ok {
// if len(defaults) > 0 {
// ret = rsmi_dev_power_cap_default_get(Device.index, &power)
// }
// }
// }
if _, ok := Device.supported["rsmi_dev_power_cap_default_get"]; ok {
ret = rsmi_dev_power_cap_default_get(Device.index, &power)
}
return power, ret
}
// GetDefaultPowerCap gets the default power cap for the device.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetDefaultPowerCap() (uint64, RSMI_status) {
return DeviceGetDefaultPowerCap(Device)
}
// DeviceGetPowerCapRange gets the range of valid values (maximum and minimum) for the power cap.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetPowerCapRange(Device DeviceHandle, Sensor uint32) (uint64, uint64, RSMI_status) {
var mini uint64 = 0
var maxi uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if sensors, ok := Device.supported["rsmi_dev_power_cap_range_get"]; ok {
if _, ok := sensors[uint64(Sensor)]; ok {
ret = rsmi_dev_power_cap_range_get(Device.index, Sensor, &maxi, &mini)
} else if defaults, ok := sensors[DEFAULT_VARIANT]; ok {
if len(defaults) > 0 {
ret = rsmi_dev_power_cap_range_get(Device.index, uint32(defaults[0]), &maxi, &mini)
}
}
}
return maxi, mini, ret
}
// GetPowerCapRange gets the range of valid values (maximum and minimum) for the power cap.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetPowerCapRange(Sensor uint32) (uint64, uint64, RSMI_status) {
return DeviceGetPowerCapRange(Device, Sensor)
}
// DeviceGetEnergyCount gets the energy accumulator counter of the device.
// It returns the power, the resolution and the timestamp.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetEnergyCount(Device DeviceHandle) (uint64, float32, uint64, RSMI_status) {
var power uint64 = 0
var resolution float32 = 0
var timestamp uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
ret = rsmi_dev_energy_count_get(Device.index, &power, &resolution, ×tamp)
// Seems to be not listed in the function-variant mapping
// if _, ok := Device.supported["rsmi_dev_energy_count_get"]; ok {
// ret = rsmi_dev_energy_count_get(Device.index, &power, &resolution, ×tamp)
// } else {
// fmt.Println("rsmi_dev_energy_count_get not available")
// }
return power, resolution, timestamp, ret
}
// GetEnergyCount gets the energy accumulator counter of the device.
// It returns the power, the resolution and the timestamp.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetEnergyCount() (uint64, float32, uint64, RSMI_status) {
return DeviceGetEnergyCount(Device)
}
// DeviceSetPowerCap sets the power cap value to a set of available settings selectable through a mask.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
// STATUS_PERMISSION function requires root access.
func DeviceSetPowerCap(Device DeviceHandle, Sensor uint32, Mask uint64) RSMI_status {
var ret RSMI_status = STATUS_NOT_SUPPORTED
if sensors, ok := Device.supported["rsmi_dev_power_cap_set"]; ok {
if _, ok := sensors[uint64(Sensor)]; ok {
ret = rsmi_dev_power_cap_set(Device.index, Sensor, Mask)
} else if defaults, ok := sensors[DEFAULT_VARIANT]; ok {
if len(defaults) > 0 {
ret = rsmi_dev_power_cap_set(Device.index, uint32(defaults[0]), Mask)
}
}
}
return ret
}
// SetPowerCap sets the power cap value to a set of available settings selectable through a mask.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
// STATUS_PERMISSION function requires root access.
func (Device DeviceHandle) SetPowerCap(Sensor uint32, Mask uint64) RSMI_status {
return DeviceSetPowerCap(Device, Sensor, Mask)
}
// DeviceSetPowerProfile set the power profile.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid. (not documented but likely).
// STATUS_PERMISSION function requires root access.
func DeviceSetPowerProfile(Device DeviceHandle, Preset RSMI_power_profile_preset_masks) RSMI_status {
var ret RSMI_status = STATUS_NOT_SUPPORTED
if _, ok := Device.supported["rsmi_dev_power_profile_set"]; ok {
ret = rsmi_dev_power_profile_set(Device.index, 0, Preset)
}
return ret
}
// SetPowerProfile set the power profile.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid. (not documented but likely).
// STATUS_PERMISSION function requires root access.
func (Device DeviceHandle) SetPowerProfile(Preset RSMI_power_profile_preset_masks) RSMI_status {
return DeviceSetPowerProfile(Device, Preset)
}
// DeviceGetTotalMemory get the total amount of memory that exists.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetTotalMemory(Device DeviceHandle, Type RSMI_memory_type) (uint64, RSMI_status) {
var size uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if types, ok := Device.supported["rsmi_dev_memory_total_get"]; ok {
if _, ok := types[uint64(Type)]; ok {
ret = rsmi_dev_memory_total_get(Device.index, Type, &size)
}
}
return size, ret
}
// GetTotalMemory get the total amount of memory that exists.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetTotalMemory(Type RSMI_memory_type) (uint64, RSMI_status) {
return DeviceGetTotalMemory(Device, Type)
}
// DeviceGetUsedMemory gets the current memory usage.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetUsedMemory(Device DeviceHandle, Type RSMI_memory_type) (uint64, RSMI_status) {
var size uint64 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if types, ok := Device.supported["rsmi_dev_memory_usage_get"]; ok {
if _, ok := types[uint64(Type)]; ok {
ret = rsmi_dev_memory_usage_get(Device.index, Type, &size)
}
}
return size, ret
}
// GetUsedMemory gets the current memory usage.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetUsedMemory(Type RSMI_memory_type) (uint64, RSMI_status) {
return DeviceGetUsedMemory(Device, Type)
}
// DeviceGetMemoryUtilization gets the percentage of time any device memory is being used.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func DeviceGetMemoryUtilization(Device DeviceHandle) (uint32, RSMI_status) {
var percent uint32 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
if _, ok := Device.supported["rsmi_dev_memory_busy_percent_get"]; ok {
ret = rsmi_dev_memory_busy_percent_get(Device.index, &percent)
}
return percent, ret
}
// GetMemoryUtilization gets the percentage of time any device memory is being used.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
func (Device DeviceHandle) GetMemoryUtilization() (uint32, RSMI_status) {
return DeviceGetMemoryUtilization(Device)
}
// DeviceGetMemoryReservedPages gets information about reserved ("retired") memory pages.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
// STATUS_INSUFFICIENT_SIZE should not happen, the size is retrieved and a big enough slice allocated.
func DeviceGetMemoryReservedPages(Device DeviceHandle) ([]RSMI_retired_page_record, RSMI_status) {
var num_records uint32 = 0
var ret RSMI_status = STATUS_NOT_SUPPORTED
records := make([]RSMI_retired_page_record, 0)
ret = rsmi_dev_memory_reserved_pages_get(Device.index, &num_records, nil)
if ret == STATUS_SUCCESS {
if num_records > 0 {
records := make([]RSMI_retired_page_record, num_records)
ret = rsmi_dev_memory_reserved_pages_get(Device.index, &num_records, &records[0])
}
}
// if _, ok := Device.supported["rsmi_dev_memory_reserved_pages_get"]; ok {
// ret = rsmi_dev_memory_reserved_pages_get(Device.index, &num_records, nil)
// if ret == STATUS_SUCCESS {
// if num_records > 0 {
// records := make([]RSMI_retired_page_record, num_records)
// ret = rsmi_dev_memory_reserved_pages_get(Device.index, &num_records, &records[0])
// }
// }
// }
return records, ret
}
// GetMemoryReservedPages gets information about reserved ("retired") memory pages.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.
// STATUS_INVALID_ARGS the provided arguments are not valid.
// STATUS_INSUFFICIENT_SIZE should not happen, the size is retrieved and a big enough slice allocated.
func (Device DeviceHandle) GetMemoryReservedPages() ([]RSMI_retired_page_record, RSMI_status) {
return DeviceGetMemoryReservedPages(Device)
}
// DeviceGetFanRpms gets the fan speed in RPMs of the device.
//
// STATUS_SUCCESS call was successful.
// STATUS_NOT_SUPPORTED installed software or hardware does not support this function with the given arguments.