forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhsa_ext_amd.h
1969 lines (1869 loc) · 71.4 KB
/
hsa_ext_amd.h
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) 2014-2020 Advanced Micro Devices Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
////////////////////////////////////////////////////////////////////////////////
// HSA AMD extension.
#ifndef HSA_RUNTIME_EXT_AMD_H_
#define HSA_RUNTIME_EXT_AMD_H_
#include "hsa.h"
#include "hsa_ext_image.h"
#define HSA_AMD_INTERFACE_VERSION_MAJOR 1
#define HSA_AMD_INTERFACE_VERSION_MINOR 0
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Enumeration constants added to ::hsa_status_t.
*
* @remark Additions to hsa_status_t
*/
enum {
/**
* The memory pool is invalid.
*/
HSA_STATUS_ERROR_INVALID_MEMORY_POOL = 40,
/**
* Agent accessed memory beyond the maximum legal address.
*/
HSA_STATUS_ERROR_MEMORY_APERTURE_VIOLATION = 41,
/**
* Agent executed an invalid shader instruction.
*/
HSA_STATUS_ERROR_ILLEGAL_INSTRUCTION = 42,
};
/**
* @brief Agent attributes.
*/
typedef enum hsa_amd_agent_info_s {
/**
* Chip identifier. The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_CHIP_ID = 0xA000,
/**
* Size of a cacheline in bytes. The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_CACHELINE_SIZE = 0xA001,
/**
* The number of compute unit available in the agent. The type of this
* attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT = 0xA002,
/**
* The maximum clock frequency of the agent in MHz. The type of this
* attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_MAX_CLOCK_FREQUENCY = 0xA003,
/**
* Internal driver node identifier. The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_DRIVER_NODE_ID = 0xA004,
/**
* Max number of watch points on memory address ranges to generate exception
* events when the watched addresses are accessed. The type of this
* attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_MAX_ADDRESS_WATCH_POINTS = 0xA005,
/**
* Agent BDF_ID, named LocationID in thunk. The type of this attribute is
* uint32_t.
*/
HSA_AMD_AGENT_INFO_BDFID = 0xA006,
/**
* Memory Interface width, the return value type is uint32_t.
* This attribute is deprecated.
*/
HSA_AMD_AGENT_INFO_MEMORY_WIDTH = 0xA007,
/**
* Max Memory Clock, the return value type is uint32_t.
*/
HSA_AMD_AGENT_INFO_MEMORY_MAX_FREQUENCY = 0xA008,
/**
* Board name of Agent - populated from MarketingName of Kfd Node
* The value is an Ascii string of 64 chars.
*/
HSA_AMD_AGENT_INFO_PRODUCT_NAME = 0xA009,
/**
* Maximum number of waves possible in a Compute Unit.
* The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU = 0xA00A,
/**
* Number of SIMD's per compute unit CU
* The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU = 0xA00B,
/**
* Number of Shader Engines (SE) in Gpu
* The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_NUM_SHADER_ENGINES = 0xA00C,
/**
* Number of Shader Arrays Per Shader Engines in Gpu
* The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_NUM_SHADER_ARRAYS_PER_SE = 0xA00D,
/**
* Address of the HDP flush registers. Use of these registers does not conform to the HSA memory
* model and should be treated with caution.
* The type of this attribute is hsa_amd_hdp_flush_t.
*/
HSA_AMD_AGENT_INFO_HDP_FLUSH = 0xA00E,
/**
* PCIe domain for the agent. Pairs with HSA_AMD_AGENT_INFO_BDFID
* to give the full physical location of the Agent.
* The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_DOMAIN = 0xA00F,
/**
* Queries for support of cooperative queues. See ::HSA_QUEUE_TYPE_COOPERATIVE.
* The type of this attribute is bool.
*/
HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES = 0xA010,
/**
* Queries UUID of an agent. The value is an Ascii string with a maximum
* of 21 chars including NUL. The string value consists of two parts: header
* and body. The header identifies device type (GPU, CPU, DSP) while body
* encodes UUID as a 16 digit hex string
*
* Agents that do not support UUID will return the string "GPU-XX" or
* "CPU-XX" or "DSP-XX" depending upon their device type ::hsa_device_type_t
*/
HSA_AMD_AGENT_INFO_UUID = 0xA011,
/**
* Queries for the ASIC revision of an agent. The value is an integer that
* increments for each revision. This can be used by user-level software to
* change how it operates, depending on the hardware version. This allows
* selective workarounds for hardware errata.
* The type of this attribute is uint32_t.
*/
HSA_AMD_AGENT_INFO_ASIC_REVISION = 0xA012
} hsa_amd_agent_info_t;
typedef struct hsa_amd_hdp_flush_s {
uint32_t* HDP_MEM_FLUSH_CNTL;
uint32_t* HDP_REG_FLUSH_CNTL;
} hsa_amd_hdp_flush_t;
/**
* @brief Region attributes.
*/
typedef enum hsa_amd_region_info_s {
/**
* Determine if host can access the region. The type of this attribute
* is bool.
*/
HSA_AMD_REGION_INFO_HOST_ACCESSIBLE = 0xA000,
/**
* Base address of the region in flat address space.
*/
HSA_AMD_REGION_INFO_BASE = 0xA001,
/**
* Memory Interface width, the return value type is uint32_t.
* This attribute is deprecated. Use HSA_AMD_AGENT_INFO_MEMORY_WIDTH.
*/
HSA_AMD_REGION_INFO_BUS_WIDTH = 0xA002,
/**
* Max Memory Clock, the return value type is uint32_t.
* This attribute is deprecated. Use HSA_AMD_AGENT_INFO_MEMORY_MAX_FREQUENCY.
*/
HSA_AMD_REGION_INFO_MAX_CLOCK_FREQUENCY = 0xA003
} hsa_amd_region_info_t;
/**
* @brief Coherency attributes of fine grain region.
*/
typedef enum hsa_amd_coherency_type_s {
/**
* Coherent region.
*/
HSA_AMD_COHERENCY_TYPE_COHERENT = 0,
/**
* Non coherent region.
*/
HSA_AMD_COHERENCY_TYPE_NONCOHERENT = 1
} hsa_amd_coherency_type_t;
/**
* @brief Get the coherency type of the fine grain region of an agent.
*
* @param[in] agent A valid agent.
*
* @param[out] type Pointer to a memory location where the HSA runtime will
* store the coherency type of the fine grain region.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p type is NULL.
*/
hsa_status_t HSA_API hsa_amd_coherency_get_type(hsa_agent_t agent,
hsa_amd_coherency_type_t* type);
/**
* @brief Set the coherency type of the fine grain region of an agent.
* Deprecated. This is supported on KV platforms. For backward compatibility
* other platforms will spuriously succeed.
*
* @param[in] agent A valid agent.
*
* @param[in] type The coherency type to be set.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p type is invalid.
*/
hsa_status_t HSA_API hsa_amd_coherency_set_type(hsa_agent_t agent,
hsa_amd_coherency_type_t type);
/**
* @brief Structure containing profiling dispatch time information.
*
* Times are reported as ticks in the domain of the HSA system clock.
* The HSA system clock tick and frequency is obtained via hsa_system_get_info.
*/
typedef struct hsa_amd_profiling_dispatch_time_s {
/**
* Dispatch packet processing start time.
*/
uint64_t start;
/**
* Dispatch packet completion time.
*/
uint64_t end;
} hsa_amd_profiling_dispatch_time_t;
/**
* @brief Structure containing profiling async copy time information.
*
* Times are reported as ticks in the domain of the HSA system clock.
* The HSA system clock tick and frequency is obtained via hsa_system_get_info.
*/
typedef struct hsa_amd_profiling_async_copy_time_s {
/**
* Async copy processing start time.
*/
uint64_t start;
/**
* Async copy completion time.
*/
uint64_t end;
} hsa_amd_profiling_async_copy_time_t;
/**
* @brief Enable or disable profiling capability of a queue.
*
* @param[in] queue A valid queue.
*
* @param[in] enable 1 to enable profiling. 0 to disable profiling.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_QUEUE The queue is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p queue is NULL.
*/
hsa_status_t HSA_API
hsa_amd_profiling_set_profiler_enabled(hsa_queue_t* queue, int enable);
/**
* @brief Enable or disable asynchronous memory copy profiling.
*
* @details The runtime will provide the copy processing start timestamp and
* completion timestamp of each call to hsa_amd_memory_async_copy if the
* async copy profiling is enabled prior to the call to
* hsa_amd_memory_async_copy. The completion signal object is used to
* hold the last async copy start and end timestamp. The client can retrieve
* these timestamps via call to hsa_amd_profiling_get_async_copy_time.
*
* @param[in] enable True to enable profiling. False to disable profiling.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES Failed on allocating resources
* needed to profile the asynchronous copy.
*/
hsa_status_t HSA_API
hsa_amd_profiling_async_copy_enable(bool enable);
/**
* @brief Retrieve packet processing time stamps.
*
* @param[in] agent The agent with which the signal was last used. For
* instance, if the profiled dispatch packet is dispatched onto queue Q,
* which was created on agent A, then this parameter must be A.
*
* @param[in] signal A signal used as the completion signal of the dispatch
* packet to retrieve time stamps from. This dispatch packet must have been
* issued to a queue with profiling enabled and have already completed. Also
* the signal must not have yet been used in any other packet following the
* completion of the profiled dispatch packet.
*
* @param[out] time Packet processing timestamps in the HSA system clock
* domain.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_SIGNAL The signal is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p time is NULL.
*/
hsa_status_t HSA_API hsa_amd_profiling_get_dispatch_time(
hsa_agent_t agent, hsa_signal_t signal,
hsa_amd_profiling_dispatch_time_t* time);
/**
* @brief Retrieve asynchronous copy timestamps.
*
* @details Async copy profiling is enabled via call to
* hsa_amd_profiling_async_copy_enable.
*
* @param[in] signal A signal used as the completion signal of the call to
* hsa_amd_memory_async_copy.
*
* @param[out] time Async copy processing timestamps in the HSA system clock
* domain.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_SIGNAL The signal is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p time is NULL.
*/
hsa_status_t HSA_API hsa_amd_profiling_get_async_copy_time(
hsa_signal_t signal, hsa_amd_profiling_async_copy_time_t* time);
/**
* @brief Computes the frequency ratio and offset between the agent clock and
* HSA system clock and converts the agent's tick to HSA system domain tick.
*
* @param[in] agent The agent used to retrieve the agent_tick. It is user's
* responsibility to make sure the tick number is from this agent, otherwise,
* the behavior is undefined.
*
* @param[in] agent_tick The tick count retrieved from the specified @p agent.
*
* @param[out] system_tick The translated HSA system domain clock counter tick.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p system_tick is NULL;
*/
hsa_status_t HSA_API
hsa_amd_profiling_convert_tick_to_system_domain(hsa_agent_t agent,
uint64_t agent_tick,
uint64_t* system_tick);
/**
* @brief Signal attribute flags.
*/
typedef enum {
/**
* Signal will only be consumed by AMD GPUs. Limits signal consumption to
* AMD GPU agents only. Ignored if @p num_consumers is not zero (all agents).
*/
HSA_AMD_SIGNAL_AMD_GPU_ONLY = 1,
/**
* Signal may be used for interprocess communication.
* IPC signals can be read, written, and waited on from any process.
* Profiling using an IPC enabled signal is only supported in a single process
* at a time. Producing profiling data in one process and consuming it in
* another process is undefined.
*/
HSA_AMD_SIGNAL_IPC = 2,
} hsa_amd_signal_attribute_t;
/**
* @brief Create a signal with specific attributes.
*
* @param[in] initial_value Initial value of the signal.
*
* @param[in] num_consumers Size of @p consumers. A value of 0 indicates that
* any agent might wait on the signal.
*
* @param[in] consumers List of agents that might consume (wait on) the
* signal. If @p num_consumers is 0, this argument is ignored; otherwise, the
* HSA runtime might use the list to optimize the handling of the signal
* object. If an agent not listed in @p consumers waits on the returned
* signal, the behavior is undefined. The memory associated with @p consumers
* can be reused or freed after the function returns.
*
* @param[in] attributes Requested signal attributes. Multiple signal attributes
* may be requested by combining them with bitwise OR. Requesting no attributes
* (@p attributes == 0) results in the same signal as would have been obtained
* via hsa_signal_create.
*
* @param[out] signal Pointer to a memory location where the HSA runtime will
* store the newly created signal handle. Must not be NULL.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to allocate
* the required resources.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p signal is NULL, @p
* num_consumers is greater than 0 but @p consumers is NULL, or @p consumers
* contains duplicates.
*/
hsa_status_t HSA_API hsa_amd_signal_create(hsa_signal_value_t initial_value, uint32_t num_consumers,
const hsa_agent_t* consumers, uint64_t attributes,
hsa_signal_t* signal);
/**
* @brief Asyncronous signal handler function type.
*
* @details Type definition of callback function to be used with
* hsa_amd_signal_async_handler. This callback is invoked if the associated
* signal and condition are met. The callback receives the value of the signal
* which satisfied the associated wait condition and a user provided value. If
* the callback returns true then the callback will be called again if the
* associated signal and condition are satisfied again. If the callback returns
* false then it will not be called again.
*
* @param[in] value Contains the value of the signal observed by
* hsa_amd_signal_async_handler which caused the signal handler to be invoked.
*
* @param[in] arg Contains the user provided value given when the signal handler
* was registered with hsa_amd_signal_async_handler
*
* @retval true resumes monitoring the signal with this handler (as if calling
* hsa_amd_signal_async_handler again with identical parameters)
*
* @retval false stops monitoring the signal with this handler (handler will
* not be called again for this signal)
*
*/
typedef bool (*hsa_amd_signal_handler)(hsa_signal_value_t value, void* arg);
/**
* @brief Register asynchronous signal handler function.
*
* @details Allows registering a callback function and user provided value with
* a signal and wait condition. The callback will be invoked if the associated
* signal and wait condition are satisfied. Callbacks will be invoked serially
* but in an arbitrary order so callbacks should be independent of each other.
* After being invoked a callback may continue to wait for its associated signal
* and condition and, possibly, be invoked again. Or the callback may stop
* waiting. If the callback returns true then it will continue waiting and may
* be called again. If false then the callback will not wait again and will not
* be called again for the associated signal and condition. It is possible to
* register the same callback multiple times with the same or different signals
* and/or conditions. Each registration of the callback will be treated entirely
* independently.
*
* @param[in] signal hsa signal to be asynchronously monitored
*
* @param[in] cond condition value to monitor for
*
* @param[in] value signal value used in condition expression
*
* @param[in] handler asynchronous signal handler invoked when signal's
* condition is met
*
* @param[in] arg user provided value which is provided to handler when handler
* is invoked
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_SIGNAL signal is not a valid hsa_signal_t
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT handler is invalid (NULL)
*
* @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime is out of
* resources or blocking signals are not supported by the HSA driver component.
*
*/
hsa_status_t HSA_API
hsa_amd_signal_async_handler(hsa_signal_t signal,
hsa_signal_condition_t cond,
hsa_signal_value_t value,
hsa_amd_signal_handler handler, void* arg);
/**
* @brief Call a function asynchronously
*
* @details Provides access to the runtime's asynchronous event handling thread
* for general asynchronous functions. Functions queued this way are executed
* in the same manner as if they were a signal handler who's signal is
* satisfied.
*
* @param[in] callback asynchronous function to be invoked
*
* @param[in] arg user provided value which is provided to handler when handler
* is invoked
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT handler is invalid (NULL)
*
* @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime is out of
* resources or blocking signals are not supported by the HSA driver component.
*
*/
hsa_status_t HSA_API
hsa_amd_async_function(void (*callback)(void* arg), void* arg);
/**
* @brief Wait for any signal-condition pair to be satisfied.
*
* @details Allows waiting for any of several signal and conditions pairs to be
* satisfied. The function returns the index into the list of signals of the
* first satisfying signal-condition pair. The value of the satisfying signal's
* value is returned in satisfying_value unless satisfying_value is NULL. This
* function provides only relaxed memory semantics.
*/
uint32_t HSA_API
hsa_amd_signal_wait_any(uint32_t signal_count, hsa_signal_t* signals,
hsa_signal_condition_t* conds,
hsa_signal_value_t* values, uint64_t timeout_hint,
hsa_wait_state_t wait_hint,
hsa_signal_value_t* satisfying_value);
/**
* @brief Query image limits.
*
* @param[in] agent A valid agent.
*
* @param[in] attribute HSA image info attribute to query.
*
* @param[out] value Pointer to an application-allocated buffer where to store
* the value of the attribute. If the buffer passed by the application is not
* large enough to hold the value of @p attribute, the behavior is undefined.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_QUEUE @p value is NULL or @p attribute <
* HSA_EXT_AGENT_INFO_IMAGE_1D_MAX_ELEMENTS or @p attribute >
* HSA_EXT_AGENT_INFO_IMAGE_ARRAY_MAX_LAYERS.
*
*/
hsa_status_t HSA_API hsa_amd_image_get_info_max_dim(hsa_agent_t agent,
hsa_agent_info_t attribute,
void* value);
/**
* @brief Set a CU affinity to specific queues within the process, this function
* call is "atomic".
*
* @param[in] queue A pointer to HSA queue.
*
* @param[in] num_cu_mask_count Size of CUMask bit array passed in.
*
* @param[in] cu_mask Bit-vector representing the CU mask.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_QUEUE @p queue is NULL or invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p num_cu_mask_count is not
* multiple of 32 or @p cu_mask is NULL.
*
* @retval ::HSA_STATUS_ERROR failed to call thunk api
*
*/
hsa_status_t HSA_API hsa_amd_queue_cu_set_mask(const hsa_queue_t* queue,
uint32_t num_cu_mask_count,
const uint32_t* cu_mask);
/**
* @brief Memory segments associated with a memory pool.
*/
typedef enum {
/**
* Global segment. Used to hold data that is shared by all agents.
*/
HSA_AMD_SEGMENT_GLOBAL = 0,
/**
* Read-only segment. Used to hold data that remains constant during the
* execution of a kernel.
*/
HSA_AMD_SEGMENT_READONLY = 1,
/**
* Private segment. Used to hold data that is local to a single work-item.
*/
HSA_AMD_SEGMENT_PRIVATE = 2,
/**
* Group segment. Used to hold data that is shared by the work-items of a
* work-group.
*/
HSA_AMD_SEGMENT_GROUP = 3,
} hsa_amd_segment_t;
/**
* @brief A memory pool encapsulates physical storage on an agent
* along with a memory access model.
*
* @details A memory pool encapsulates a physical partition of an agent's
* memory system along with a memory access model. Division of a single
* memory system into separate pools allows querying each partition's access
* path properties (see ::hsa_amd_agent_memory_pool_get_info). Allocations
* from a pool are preferentially bound to that pool's physical partition.
* Binding to the pool's preferential physical partition may not be
* possible or persistent depending on the system's memory policy
* and/or state which is beyond the scope of HSA APIs.
*
* For example, a multi-node NUMA memory system may be represented by multiple
* pool's with each pool providing size and access path information for the
* partition it represents. Allocations from a pool are preferentially bound
* to the pool's partition (which in this example is a NUMA node) while
* following its memory access model. The actual placement may vary or migrate
* due to the system's NUMA policy and state, which is beyond the scope of
* HSA APIs.
*/
typedef struct hsa_amd_memory_pool_s {
/**
* Opaque handle.
*/
uint64_t handle;
} hsa_amd_memory_pool_t;
typedef enum hsa_amd_memory_pool_global_flag_s {
/**
* The application can use allocations in the memory pool to store kernel
* arguments, and provide the values for the kernarg segment of
* a kernel dispatch.
*/
HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT = 1,
/**
* Updates to memory in this pool conform to HSA memory consistency model.
* If this flag is set, then ::HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_COARSE_GRAINED
* must not be set.
*/
HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_FINE_GRAINED = 2,
/**
* Writes to memory in this pool can be performed by a single agent at a time.
*/
HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_COARSE_GRAINED = 4
} hsa_amd_memory_pool_global_flag_t;
/**
* @brief Memory pool features.
*/
typedef enum {
/**
* Segment where the memory pool resides. The type of this attribute is
* ::hsa_amd_segment_t.
*/
HSA_AMD_MEMORY_POOL_INFO_SEGMENT = 0,
/**
* Flag mask. The value of this attribute is undefined if the value of
* ::HSA_AMD_MEMORY_POOL_INFO_SEGMENT is not ::HSA_AMD_SEGMENT_GLOBAL. The type
* of
* this attribute is uint32_t, a bit-field of
* ::hsa_amd_memory_pool_global_flag_t
* values.
*/
HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS = 1,
/**
* Size of this pool, in bytes. The type of this attribute is size_t.
*/
HSA_AMD_MEMORY_POOL_INFO_SIZE = 2,
/**
* Indicates whether memory in this pool can be allocated using
* ::hsa_amd_memory_pool_allocate. The type of this attribute is bool.
*
* The value of this flag is always false for memory pools in the group and
* private segments.
*/
HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED = 5,
/**
* Allocation granularity of buffers allocated by
* ::hsa_amd_memory_pool_allocate
* in this memory pool. The size of a buffer allocated in this pool is a
* multiple of the value of this attribute. The value of this attribute is
* only defined if ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED is true for
* this pool. The type of this attribute is size_t.
*/
HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_GRANULE = 6,
/**
* Alignment of buffers allocated by ::hsa_amd_memory_pool_allocate in this
* pool. The value of this attribute is only defined if
* ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED is true for this pool, and
* must be a power of 2. The type of this attribute is size_t.
*/
HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALIGNMENT = 7,
/**
* This memory_pool can be made directly accessible by all the agents in the
* system (::hsa_amd_agent_memory_pool_get_info does not return
* ::HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED for any agent). The type of this
* attribute is bool.
*/
HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL = 15,
/**
* Maximum aggregate allocation size in bytes. The type of this attribute
* is size_t.
*/
HSA_AMD_MEMORY_POOL_INFO_ALLOC_MAX_SIZE = 16,
} hsa_amd_memory_pool_info_t;
/**
* @brief Get the current value of an attribute of a memory pool.
*
* @param[in] memory_pool A valid memory pool.
*
* @param[in] attribute Attribute to query.
*
* @param[out] value Pointer to a application-allocated buffer where to store
* the value of the attribute. If the buffer passed by the application is not
* large enough to hold the value of @p attribute, the behavior is undefined.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
*/
hsa_status_t HSA_API
hsa_amd_memory_pool_get_info(hsa_amd_memory_pool_t memory_pool,
hsa_amd_memory_pool_info_t attribute,
void* value);
/**
* @brief Iterate over the memory pools associated with a given agent, and
* invoke an application-defined callback on every iteration.
*
* @details An agent can directly access buffers located in some memory pool, or
* be enabled to access them by the application (see ::hsa_amd_agents_allow_access),
* yet that memory pool may not be returned by this function for that given
* agent.
*
* A memory pool of fine-grained type must be associated only with the host.
*
* @param[in] agent A valid agent.
*
* @param[in] callback Callback to be invoked on the same thread that called
* ::hsa_amd_agent_iterate_memory_pools, serially, once per memory pool that is
* associated with the agent. The HSA runtime passes two arguments to the
* callback: the memory pool, and the application data. If @p callback
* returns a status other than ::HSA_STATUS_SUCCESS for a particular iteration,
* the traversal stops and ::hsa_amd_agent_iterate_memory_pools returns that status
* value.
*
* @param[in] data Application data that is passed to @p callback on every
* iteration. May be NULL.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL.
*/
hsa_status_t HSA_API hsa_amd_agent_iterate_memory_pools(
hsa_agent_t agent,
hsa_status_t (*callback)(hsa_amd_memory_pool_t memory_pool, void* data),
void* data);
/**
* @brief Allocate a block of memory (or buffer) in the specified pool.
*
* @param[in] memory_pool Memory pool where to allocate memory from. The memory
* pool must have the ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED flag set.
*
* @param[in] size Allocation size, in bytes. Must not be zero. This value is
* rounded up to the nearest multiple of
* ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_GRANULE in @p memory_pool.
*
* @param[in] flags A bit-field that is used to specify allocation
* directives. Reserved parameter, must be 0.
*
* @param[out] ptr Pointer to the location where to store the base virtual
* address of
* the allocated block. The returned base address is aligned to the value of
* ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALIGNMENT in @p memory_pool. If the
* allocation fails, the returned value is undefined.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES No memory is available.
*
* @retval ::HSA_STATUS_ERROR_INVALID_MEMORY_POOL The memory pool is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ALLOCATION The host is not allowed to
* allocate memory in @p memory_pool, or @p size is greater than
* the value of HSA_AMD_MEMORY_POOL_INFO_ALLOC_MAX_SIZE in @p memory_pool.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p ptr is NULL, or @p size is 0,
* or flags is not 0.
*
*/
hsa_status_t HSA_API
hsa_amd_memory_pool_allocate(hsa_amd_memory_pool_t memory_pool, size_t size,
uint32_t flags, void** ptr);
/**
* @brief Deallocate a block of memory previously allocated using
* ::hsa_amd_memory_pool_allocate.
*
* @param[in] ptr Pointer to a memory block. If @p ptr does not match a value
* previously returned by ::hsa_amd_memory_pool_allocate, the behavior is undefined.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
*/
hsa_status_t HSA_API hsa_amd_memory_pool_free(void* ptr);
/**
* @brief Asynchronously copy a block of memory from the location pointed to by
* @p src on the @p src_agent to the memory block pointed to by @p dst on the @p
* dst_agent.
* Because the DMA engines used may not be in the same coherency domain, the caller must ensure
* that buffers are system-level coherent. In general this requires the sending device to have
* released the buffer to system scope prior to executing the copy API and the receiving device
* must execute a system scope acquire fence prior to use of the destination buffer.
*
* @param[out] dst Buffer where the content is to be copied.
*
* @param[in] dst_agent Agent associated with the @p dst. The agent must be able to directly
* access both the source and destination buffers in their current locations.
*
* @param[in] src A valid pointer to the source of data to be copied. The source
* buffer must not overlap with the destination buffer, otherwise the copy will succeed
* but contents of @p dst is undefined.
*
* @param[in] src_agent Agent associated with the @p src. The agent must be able to directly
* access both the source and destination buffers in their current locations.
*
* @param[in] size Number of bytes to copy. If @p size is 0, no copy is
* performed and the function returns success. Copying a number of bytes larger
* than the size of the buffers pointed by @p dst or @p src results in undefined
* behavior.
*
* @param[in] num_dep_signals Number of dependent signals. Can be 0.
*
* @param[in] dep_signals List of signals that must be waited on before the copy
* operation starts. The copy will start after every signal has been observed with
* the value 0. The dependent signal should not include completion signal from hsa_amd_memory_async_copy
* operation to be issued in future as that can result in a deadlock. If @p num_dep_signals is 0, this
* argument is ignored.
*
* @param[in] completion_signal Signal used to indicate completion of the copy
* operation. When the copy operation is finished, the value of the signal is
* decremented. The runtime indicates that an error has occurred during the copy
* operation by setting the value of the completion signal to a negative
* number. The signal handle must not be 0.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. The
* application is responsible for checking for asynchronous error conditions
* (see the description of @p completion_signal).
*
* @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
* initialized.
*
* @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_SIGNAL @p completion_signal is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT The source or destination
* pointers are NULL, or the completion signal is 0.
*/
hsa_status_t HSA_API
hsa_amd_memory_async_copy(void* dst, hsa_agent_t dst_agent, const void* src,
hsa_agent_t src_agent, size_t size,
uint32_t num_dep_signals,
const hsa_signal_t* dep_signals,
hsa_signal_t completion_signal);
/*
[Provisional API]
Pitched memory descriptor.
All elements must be 4 byte aligned. Pitch and slice are in bytes.
*/
typedef struct hsa_pitched_ptr_s {
void* base;
size_t pitch;
size_t slice;
} hsa_pitched_ptr_t;
/*
[Provisional API]
Copy direction flag.
*/
typedef enum {
hsaHostToHost = 0,
hsaHostToDevice = 1,
hsaDeviceToHost = 2,
hsaDeviceToDevice = 3
} hsa_amd_copy_direction_t;
/*
[Provisional API]
SDMA 3D memory copy API. The same requirements must be met by src and dst as in
hsa_amd_memory_async_copy.
Both src and dst must be directly accessible to the copy_agent during the copy, src and dst rects
must not overlap.
CPU agents are not supported. API requires SDMA and will return an error if SDMA is not available.
Offsets and range carry x in bytes, y and z in rows and layers.
*/
hsa_status_t HSA_API hsa_amd_memory_async_copy_rect(
const hsa_pitched_ptr_t* dst, const hsa_dim3_t* dst_offset, const hsa_pitched_ptr_t* src,
const hsa_dim3_t* src_offset, const hsa_dim3_t* range, hsa_agent_t copy_agent,
hsa_amd_copy_direction_t dir, uint32_t num_dep_signals, const hsa_signal_t* dep_signals,
hsa_signal_t completion_signal);
/**
* @brief Type of accesses to a memory pool from a given agent.
*/
typedef enum {
/**
* The agent cannot directly access any buffer in the memory pool.
*/
HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED = 0,
/**
* The agent can directly access a buffer located in the pool; the application
* does not need to invoke ::hsa_amd_agents_allow_access.
*/
HSA_AMD_MEMORY_POOL_ACCESS_ALLOWED_BY_DEFAULT = 1,
/**
* The agent can directly access a buffer located in the pool, but only if the
* application has previously requested access to that buffer using
* ::hsa_amd_agents_allow_access.
*/