-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhsa.h
3732 lines (3503 loc) · 121 KB
/
hsa.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 2014 ADVANCED MICRO DEVICES, INC.
//
// AMD is granting you permission to use this software and documentation(if any)
// (collectively, the "Materials") pursuant to the terms and conditions of the
// Software License Agreement included with the Materials.If you do not have a
// copy of the Software License Agreement, contact your AMD representative for a
// copy.
//
// You agree that you will not reverse engineer or decompile the Materials, in
// whole or in part, except as allowed by applicable law.
//
// WARRANTY DISCLAIMER : THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND.AMD DISCLAIMS ALL WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY,
// INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE, NON - INFRINGEMENT, THAT THE
// SOFTWARE WILL RUN UNINTERRUPTED OR ERROR - FREE OR WARRANTIES ARISING FROM
// CUSTOM OF TRADE OR COURSE OF USAGE.THE ENTIRE RISK ASSOCIATED WITH THE USE OF
// THE SOFTWARE IS ASSUMED BY YOU.Some jurisdictions do not allow the exclusion
// of implied warranties, so the above exclusion may not apply to You.
//
// LIMITATION OF LIABILITY AND INDEMNIFICATION : AMD AND ITS LICENSORS WILL NOT,
// UNDER ANY CIRCUMSTANCES BE LIABLE TO YOU FOR ANY PUNITIVE, DIRECT,
// INCIDENTAL, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM USE OF
// THE SOFTWARE OR THIS AGREEMENT EVEN IF AMD AND ITS LICENSORS HAVE BEEN
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.In no event shall AMD's total
// liability to You for all damages, losses, and causes of action (whether in
// contract, tort (including negligence) or otherwise) exceed the amount of $100
// USD. You agree to defend, indemnify and hold harmless AMD and its licensors,
// and any of their directors, officers, employees, affiliates or agents from
// and against any and all loss, damage, liability and other expenses (including
// reasonable attorneys' fees), resulting from Your use of the Software or
// violation of the terms and conditions of this Agreement.
//
// U.S.GOVERNMENT RESTRICTED RIGHTS : The Materials are provided with
// "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is
// subject to the restrictions as set forth in FAR 52.227 - 14 and DFAR252.227 -
// 7013, et seq., or its successor.Use of the Materials by the Government
// constitutes acknowledgement of AMD's proprietary rights in them.
//
// EXPORT RESTRICTIONS: The Materials may be subject to export restrictions as
// stated in the Software License Agreement.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef HSA_RUNTIME_INC_HSA_H_
#define HSA_RUNTIME_INC_HSA_H_
#include <stddef.h> /* size_t */
#include <stdint.h> /* uintXX_t */
#ifndef __cplusplus
#include <stdbool.h>
#endif /* __cplusplus */
// Placeholder for calling convention and import/export macros
#ifndef HSA_CALL
#define HSA_CALL
#endif
#ifndef HSA_EXPORT_DECORATOR
#ifdef __GNUC__
#define HSA_EXPORT_DECORATOR __attribute__ ((visibility ("default")))
#else
#define HSA_EXPORT_DECORATOR
#endif
#endif
#define HSA_API_EXPORT HSA_EXPORT_DECORATOR HSA_CALL
#define HSA_API_IMPORT HSA_CALL
#if !defined(HSA_API) && defined(HSA_EXPORT)
#define HSA_API HSA_API_EXPORT
#else
#define HSA_API HSA_API_IMPORT
#endif
// Detect and set large model builds.
#undef HSA_LARGE_MODEL
#if defined(__LP64__) || defined(_M_X64)
#define HSA_LARGE_MODEL
#endif
// Try to detect CPU endianness
#if !defined(LITTLEENDIAN_CPU) && !defined(BIGENDIAN_CPU)
#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \
defined(_M_X64)
#define LITTLEENDIAN_CPU
#endif
#endif
#undef HSA_LITTLE_ENDIAN
#if defined(LITTLEENDIAN_CPU)
#define HSA_LITTLE_ENDIAN
#elif defined(BIGENDIAN_CPU)
#else
#error "BIGENDIAN_CPU or LITTLEENDIAN_CPU must be defined"
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** \defgroup status Runtime Notifications
* @{
*/
/**
* @brief Status codes.
*/
typedef enum {
/**
* The function has been executed successfully.
*/
HSA_STATUS_SUCCESS = 0x0,
/**
* A traversal over a list of elements has been interrupted by the
* application before completing.
*/
HSA_STATUS_INFO_BREAK = 0x1,
/**
* A generic error has occurred.
*/
HSA_STATUS_ERROR = 0x1000,
/**
* One of the actual arguments does not meet a precondition stated in the
* documentation of the corresponding formal argument.
*/
HSA_STATUS_ERROR_INVALID_ARGUMENT = 0x1001,
/**
* The requested queue creation is not valid.
*/
HSA_STATUS_ERROR_INVALID_QUEUE_CREATION = 0x1002,
/**
* The requested allocation is not valid.
*/
HSA_STATUS_ERROR_INVALID_ALLOCATION = 0x1003,
/**
* The agent is invalid.
*/
HSA_STATUS_ERROR_INVALID_AGENT = 0x1004,
/**
* The memory region is invalid.
*/
HSA_STATUS_ERROR_INVALID_REGION = 0x1005,
/**
* The signal is invalid.
*/
HSA_STATUS_ERROR_INVALID_SIGNAL = 0x1006,
/**
* The queue is invalid.
*/
HSA_STATUS_ERROR_INVALID_QUEUE = 0x1007,
/**
* The HSA runtime failed to allocate the necessary resources. This error
* may also occur when the HSA runtime needs to spawn threads or create
* internal OS-specific events.
*/
HSA_STATUS_ERROR_OUT_OF_RESOURCES = 0x1008,
/**
* The AQL packet is malformed.
*/
HSA_STATUS_ERROR_INVALID_PACKET_FORMAT = 0x1009,
/**
* An error has been detected while releasing a resource.
*/
HSA_STATUS_ERROR_RESOURCE_FREE = 0x100A,
/**
* An API other than ::hsa_init has been invoked while the reference count
* of the HSA runtime is 0.
*/
HSA_STATUS_ERROR_NOT_INITIALIZED = 0x100B,
/**
* The maximum reference count for the object has been reached.
*/
HSA_STATUS_ERROR_REFCOUNT_OVERFLOW = 0x100C,
/**
* The arguments passed to a functions are not compatible.
*/
HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS = 0x100D,
/**
* The index is invalid.
*/
HSA_STATUS_ERROR_INVALID_INDEX = 0x100E,
/**
* The instruction set architecture is invalid.
*/
HSA_STATUS_ERROR_INVALID_ISA = 0x100F,
/**
* The instruction set architecture name is invalid.
*/
HSA_STATUS_ERROR_INVALID_ISA_NAME = 0x1017,
/**
* The code object is invalid.
*/
HSA_STATUS_ERROR_INVALID_CODE_OBJECT = 0x1010,
/**
* The executable is invalid.
*/
HSA_STATUS_ERROR_INVALID_EXECUTABLE = 0x1011,
/**
* The executable is frozen.
*/
HSA_STATUS_ERROR_FROZEN_EXECUTABLE = 0x1012,
/**
* There is no symbol with the given name.
*/
HSA_STATUS_ERROR_INVALID_SYMBOL_NAME = 0x1013,
/**
* The variable is already defined.
*/
HSA_STATUS_ERROR_VARIABLE_ALREADY_DEFINED = 0x1014,
/**
* The variable is undefined.
*/
HSA_STATUS_ERROR_VARIABLE_UNDEFINED = 0x1015,
/**
* An HSAIL operation resulted on a hardware exception.
*/
HSA_STATUS_ERROR_EXCEPTION = 0x1016
} hsa_status_t;
/**
* @brief Query additional information about a status code.
*
* @param[in] status Status code.
*
* @param[out] status_string A NUL-terminated string that describes the error
* status.
*
* @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 @p status is an invalid
* status code, or @p status_string is NULL.
*/
hsa_status_t HSA_API
hsa_status_string(hsa_status_t status, const char **status_string);
/** @} */
/** \defgroup common Common Definitions
* @{
*/
/**
* @brief Three-dimensional coordinate.
*/
typedef struct hsa_dim3_s {
/**
* X dimension.
*/
uint32_t x;
/**
* Y dimension.
*/
uint32_t y;
/**
* Z dimension.
*/
uint32_t z;
} hsa_dim3_t;
/**
* @brief Access permissions.
*/
typedef enum {
/**
* Read-only access.
*/
HSA_ACCESS_PERMISSION_RO = 1,
/**
* Write-only access.
*/
HSA_ACCESS_PERMISSION_WO = 2,
/**
* Read and write access.
*/
HSA_ACCESS_PERMISSION_RW = 3
} hsa_access_permission_t;
/** @} **/
/** \defgroup initshutdown Initialization and Shut Down
* @{
*/
/**
* @brief Initialize the HSA runtime.
*
* @details Initializes the HSA runtime if it is not already initialized, and
* increases the reference counter associated with the HSA runtime for the
* current process. Invocation of any HSA function other than ::hsa_init results
* in undefined behavior if the current HSA runtime reference counter is less
* than one.
*
* @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
*
* @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES There is failure to allocate
* the resources required by the implementation.
*
* @retval ::HSA_STATUS_ERROR_REFCOUNT_OVERFLOW The HSA runtime reference
* count reaches INT32_MAX.
*/
hsa_status_t HSA_API hsa_init(void);
/**
* @brief Shut down the HSA runtime.
*
* @details Decreases the reference count of the HSA runtime instance. When the
* reference count reaches 0, the HSA runtime is no longer considered valid
* but the application might call ::hsa_init to initialize the HSA runtime
* again.
*
* Once the reference count of the HSA runtime reaches 0, all the resources
* associated with it (queues, signals, agent information, etc.) are
* considered invalid and any attempt to reference them in subsequent API calls
* results in undefined behavior. When the reference count reaches 0, the HSA
* runtime may release resources associated with it.
*
* @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_shut_down(void);
/** @} **/
/** \defgroup agentinfo System and Agent Information
* @{
*/
/**
* @brief Endianness. A convention used to interpret the bytes making up a data
* word.
*/
typedef enum {
/**
* The least significant byte is stored in the smallest address.
*/
HSA_ENDIANNESS_LITTLE = 0,
/**
* The most significant byte is stored in the smallest address.
*/
HSA_ENDIANNESS_BIG = 1
} hsa_endianness_t;
/**
* @brief Machine model. A machine model determines the size of certain data
* types in HSA runtime and an agent.
*/
typedef enum {
/**
* Small machine model. Addresses use 32 bits.
*/
HSA_MACHINE_MODEL_SMALL = 0,
/**
* Large machine model. Addresses use 64 bits.
*/
HSA_MACHINE_MODEL_LARGE = 1
} hsa_machine_model_t;
/**
* @brief Profile. A profile indicates a particular level of feature
* support. For example, in the base profile the application must use the HSA
* runtime allocator to reserve Shared Virtual Memory, while in the full profile
* any host pointer can be shared across all the agents.
*/
typedef enum {
/**
* Base profile.
*/
HSA_PROFILE_BASE = 0,
/**
* Full profile.
*/
HSA_PROFILE_FULL = 1
} hsa_profile_t;
/**
* @brief System attributes.
*/
typedef enum {
/**
* Major version of the HSA runtime specification supported by the
* implementation. The type of this attribute is uint16_t.
*/
HSA_SYSTEM_INFO_VERSION_MAJOR = 0,
/**
* Minor version of the HSA runtime specification supported by the
* implementation. The type of this attribute is uint16_t.
*/
HSA_SYSTEM_INFO_VERSION_MINOR = 1,
/**
* Current timestamp. The value of this attribute monotonically increases at a
* constant rate. The type of this attribute is uint64_t.
*/
HSA_SYSTEM_INFO_TIMESTAMP = 2,
/**
* Timestamp value increase rate, in Hz. The timestamp (clock) frequency is
* in the range 1-400MHz. The type of this attribute is uint64_t.
*/
HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY = 3,
/**
* Maximum duration of a signal wait operation. Expressed as a count based on
* the timestamp frequency. The type of this attribute is uint64_t.
*/
HSA_SYSTEM_INFO_SIGNAL_MAX_WAIT = 4,
/**
* Endianness of the system. The type of this attribute us ::hsa_endianness_t.
*/
HSA_SYSTEM_INFO_ENDIANNESS = 5,
/**
* Machine model supported by the HSA runtime. The type of this attribute is
* ::hsa_machine_model_t.
*/
HSA_SYSTEM_INFO_MACHINE_MODEL = 6,
/**
* Bit-mask indicating which extensions are supported by the
* implementation. An extension with an ID of @p i is supported if the bit at
* position @p i is set. The type of this attribute is uint8_t[128].
*/
HSA_SYSTEM_INFO_EXTENSIONS = 7
} hsa_system_info_t;
/**
* @brief Get the current value of a system attribute.
*
* @param[in] attribute 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_ARGUMENT @p attribute is an invalid
* system attribute, or @p value is NULL.
*/
hsa_status_t HSA_API
hsa_system_get_info(hsa_system_info_t attribute, void *value);
/**
* @brief HSA extensions.
*/
typedef enum {
/**
* Finalizer extension.
*/
HSA_EXTENSION_FINALIZER = 0,
/**
* Images extension.
*/
HSA_EXTENSION_IMAGES = 1,
HSA_EXTENSION_AMD_PROFILER = 2
} hsa_extension_t;
/**
* @brief Query if a given version of an extension is supported by the HSA
* implementation.
*
* @param[in] extension Extension identifier.
*
* @param[in] version_major Major version number.
*
* @param[in] version_minor Minor version number.
*
* @param[out] result Pointer to a memory location where the HSA runtime stores
* the result of the check. The result is true if the specified version of the
* extension is supported, and false otherwise.
*
* @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 @p extension is not a valid
* extension, or @p result is NULL.
*/
hsa_status_t HSA_API
hsa_system_extension_supported(uint16_t extension, uint16_t version_major,
uint16_t version_minor, bool *result);
/**
* @brief Retrieve the function pointers corresponding to a given version of an
* extension. Portable applications are expected to invoke the extension API
* using the returned function pointers
*
* @details The application is responsible for verifying that the given version
* of the extension is supported by the HSA implementation (see
* ::hsa_system_extension_supported). If the given combination of extension,
* major version, and minor version is not supported by the implementation, the
* behavior is undefined.
*
* @param[in] extension Extension identifier.
*
* @param[in] version_major Major version number for which to retrieve the
* function pointer table.
*
* @param[in] version_minor Minor version number for which to retrieve the
* function pointer table.
*
* @param[out] table Pointer to an application-allocated function pointer table
* that is populated by the HSA runtime. Must not be NULL. The memory associated
* with table can be reused or freed after the function returns.
*
* @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 @p extension is not a valid
* extension, or @p table is NULL.
*/
hsa_status_t HSA_API
hsa_system_get_extension_table(uint16_t extension, uint16_t version_major,
uint16_t version_minor, void *table);
/**
* @brief Opaque handle representing an agent, a device that participates in
* the HSA memory model. An agent can submit AQL packets for execution, and
* may also accept AQL packets for execution (agent dispatch packets or kernel
* dispatch packets launching HSAIL-derived binaries).
*/
typedef struct hsa_agent_s {
/**
* Opaque handle.
*/
uint64_t handle;
} hsa_agent_t;
/**
* @brief Agent features.
*/
typedef enum {
/**
* The agent supports AQL packets of kernel dispatch type. If this
* feature is enabled, the agent is also a kernel agent.
*/
HSA_AGENT_FEATURE_KERNEL_DISPATCH = 1,
/**
* The agent supports AQL packets of agent dispatch type.
*/
HSA_AGENT_FEATURE_AGENT_DISPATCH = 2
} hsa_agent_feature_t;
/**
* @brief Hardware device type.
*/
typedef enum {
/**
* CPU device.
*/
HSA_DEVICE_TYPE_CPU = 0,
/**
* GPU device.
*/
HSA_DEVICE_TYPE_GPU = 1,
/**
* DSP device.
*/
HSA_DEVICE_TYPE_DSP = 2
} hsa_device_type_t;
/**
* @brief Default floating-point rounding mode.
*/
typedef enum {
/**
* Use a default floating-point rounding mode specified elsewhere.
*/
HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT = 0,
/**
* Operations that specify the default floating-point mode are rounded to zero
* by default.
*/
HSA_DEFAULT_FLOAT_ROUNDING_MODE_ZERO = 1,
/**
* Operations that specify the default floating-point mode are rounded to the
* nearest representable number and that ties should be broken by selecting
* the value with an even least significant bit.
*/
HSA_DEFAULT_FLOAT_ROUNDING_MODE_NEAR = 2
} hsa_default_float_rounding_mode_t;
/**
* @brief Agent attributes.
*/
typedef enum {
/**
* Agent name. The type of this attribute is a NUL-terminated char[64]. If
* the name of the agent uses less than 63 characters, the rest of the
* array must be filled with NULs.
*/
HSA_AGENT_INFO_NAME = 0,
/**
* Name of vendor. The type of this attribute is a NUL-terminated char[64]. If
* the name of the vendor uses less than 63 characters, the rest of the array
* must be filled with NULs.
*/
HSA_AGENT_INFO_VENDOR_NAME = 1,
/**
* Agent capability. The type of this attribute is ::hsa_agent_feature_t.
*/
HSA_AGENT_INFO_FEATURE = 2,
/**
* Machine model supported by the agent. The type of this attribute is
* ::hsa_machine_model_t.
*/
HSA_AGENT_INFO_MACHINE_MODEL = 3,
/**
* Profile supported by the agent. The type of this attribute is
* ::hsa_profile_t.
*/
HSA_AGENT_INFO_PROFILE = 4,
/**
* Default floating-point rounding mode. The type of this attribute is
* ::hsa_default_float_rounding_mode_t, but the value
* ::HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT is not allowed.
*/
HSA_AGENT_INFO_DEFAULT_FLOAT_ROUNDING_MODE = 5,
/**
* Default floating-point rounding modes supported by the agent in the Base
* profile. The type of this attribute is a mask of
* ::hsa_default_float_rounding_mode_t. The default floating-point rounding
* mode (::HSA_AGENT_INFO_DEFAULT_FLOAT_ROUNDING_MODE) bit must not be set.
*/
HSA_AGENT_INFO_BASE_PROFILE_DEFAULT_FLOAT_ROUNDING_MODES = 23,
/**
* Flag indicating that the f16 HSAIL operation is at least as fast as the
* f32 operation in the current agent. The value of this attribute is
* undefined if the agent is not a kernel agent. The type of this
* attribute is bool.
*/
HSA_AGENT_INFO_FAST_F16_OPERATION = 24,
/**
* Number of work-items in a wavefront. Must be a power of 2 in the range
* [1,256]. The value of this attribute is undefined if the agent is not
* a kernel agent. The type of this attribute is uint32_t.
*/
HSA_AGENT_INFO_WAVEFRONT_SIZE = 6,
/**
* Maximum number of work-items of each dimension of a work-group. Each
* maximum must be greater than 0. No maximum can exceed the value of
* ::HSA_AGENT_INFO_WORKGROUP_MAX_SIZE. The value of this attribute is
* undefined if the agent is not a kernel agent. The type of this
* attribute is uint16_t[3].
*/
HSA_AGENT_INFO_WORKGROUP_MAX_DIM = 7,
/**
* Maximum total number of work-items in a work-group. The value of this
* attribute is undefined if the agent is not a kernel agent. The type
* of this attribute is uint32_t.
*/
HSA_AGENT_INFO_WORKGROUP_MAX_SIZE = 8,
/**
* Maximum number of work-items of each dimension of a grid. Each maximum must
* be greater than 0, and must not be smaller than the corresponding value in
* ::HSA_AGENT_INFO_WORKGROUP_MAX_DIM. No maximum can exceed the value of
* ::HSA_AGENT_INFO_GRID_MAX_SIZE. The value of this attribute is undefined if
* the agent is not a kernel agent. The type of this attribute is
* ::hsa_dim3_t.
*/
HSA_AGENT_INFO_GRID_MAX_DIM = 9,
/**
* Maximum total number of work-items in a grid. The value of this attribute
* is undefined if the agent is not a kernel agent. The type of this
* attribute is uint32_t.
*/
HSA_AGENT_INFO_GRID_MAX_SIZE = 10,
/**
* Maximum number of fbarriers per work-group. Must be at least 32. The value
* of this attribute is undefined if the agent is not a kernel agent. The
* type of this attribute is uint32_t.
*/
HSA_AGENT_INFO_FBARRIER_MAX_SIZE = 11,
/**
* Maximum number of queues that can be active (created but not destroyed) at
* one time in the agent. The type of this attribute is uint32_t.
*/
HSA_AGENT_INFO_QUEUES_MAX = 12,
/**
* Minimum number of packets that a queue created in the agent
* can hold. Must be a power of 2 greater than 0. Must not exceed
* the value of ::HSA_AGENT_INFO_QUEUE_MAX_SIZE. The type of this
* attribute is uint32_t.
*/
HSA_AGENT_INFO_QUEUE_MIN_SIZE = 13,
/**
* Maximum number of packets that a queue created in the agent can
* hold. Must be a power of 2 greater than 0. The type of this attribute
* is uint32_t.
*/
HSA_AGENT_INFO_QUEUE_MAX_SIZE = 14,
/**
* Type of a queue created in the agent. The type of this attribute is
* ::hsa_queue_type_t.
*/
HSA_AGENT_INFO_QUEUE_TYPE = 15,
/**
* Identifier of the NUMA node associated with the agent. The type of this
* attribute is uint32_t.
*/
HSA_AGENT_INFO_NODE = 16,
/**
* Type of hardware device associated with the agent. The type of this
* attribute is ::hsa_device_type_t.
*/
HSA_AGENT_INFO_DEVICE = 17,
/**
* Array of data cache sizes (L1..L4). Each size is expressed in bytes. A size
* of 0 for a particular level indicates that there is no cache information
* for that level. The type of this attribute is uint32_t[4].
*/
HSA_AGENT_INFO_CACHE_SIZE = 18,
/**
* Instruction set architecture of the agent. The type of this attribute
* is ::hsa_isa_t.
*/
HSA_AGENT_INFO_ISA = 19,
/**
* Bit-mask indicating which extensions are supported by the agent. An
* extension with an ID of @p i is supported if the bit at position @p i is
* set. The type of this attribute is uint8_t[128].
*/
HSA_AGENT_INFO_EXTENSIONS = 20,
/**
* Major version of the HSA runtime specification supported by the
* agent. The type of this attribute is uint16_t.
*/
HSA_AGENT_INFO_VERSION_MAJOR = 21,
/**
* Minor version of the HSA runtime specification supported by the
* agent. The type of this attribute is uint16_t.
*/
HSA_AGENT_INFO_VERSION_MINOR = 22
} hsa_agent_info_t;
/**
* @brief Get the current value of an attribute for a given agent.
*
* @param[in] agent A valid agent.
*
* @param[in] attribute 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_AGENT The agent is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p attribute is an invalid
* agent attribute, or @p value is NULL.
*/
hsa_status_t HSA_API hsa_agent_get_info(hsa_agent_t agent,
hsa_agent_info_t attribute,
void *value);
/**
* @brief Iterate over the available agents, and invoke an
* application-defined callback on every iteration.
*
* @param[in] callback Callback to be invoked once per agent. The HSA
* runtime passes two arguments to the callback, the agent and the
* application data. If @p callback returns a status other than
* ::HSA_STATUS_SUCCESS for a particular iteration, the traversal stops and
* ::hsa_iterate_agents 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_ARGUMENT @p callback is NULL.
*/
hsa_status_t HSA_API
hsa_iterate_agents(hsa_status_t (*callback)(hsa_agent_t agent, void *data),
void *data);
/*
// If we do not know the size of an attribute, we need to query it first
// Note: this API will not be in the spec unless needed
hsa_status_t HSA_API hsa_agent_get_info_size(
hsa_agent_t agent,
hsa_agent_info_t attribute,
size_t* size);
// Set the value of an agents attribute
// Note: this API will not be in the spec unless needed
hsa_status_t HSA_API hsa_agent_set_info(
hsa_agent_t agent,
hsa_agent_info_t attribute,
void* value);
*/
/**
* @brief Exception policies applied in the presence of hardware exceptions.
*/
typedef enum {
/**
* If a hardware exception is detected, a work-item signals an exception.
*/
HSA_EXCEPTION_POLICY_BREAK = 1,
/**
* If a hardware exception is detected, a hardware status bit is set.
*/
HSA_EXCEPTION_POLICY_DETECT = 2
} hsa_exception_policy_t;
/**
* @brief Retrieve the exception policy support for a given combination of
* agent and profile
*
* @param[in] agent Agent.
*
* @param[in] profile Profile.
*
* @param[out] mask Pointer to a memory location where the HSA runtime stores a
* mask of ::hsa_exception_policy_t values. 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_INVALID_AGENT The agent is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p profile is not a valid
* profile, or @p mask is NULL.
*
*/
hsa_status_t HSA_API hsa_agent_get_exception_policies(hsa_agent_t agent,
hsa_profile_t profile,
uint16_t *mask);
/**
* @brief Query if a given version of an extension is supported by an agent
*
* @param[in] extension Extension identifier.
*
* @param[in] agent Agent.
*
* @param[in] version_major Major version number.
*
* @param[in] version_minor Minor version number.
*
* @param[out] result Pointer to a memory location where the HSA runtime stores
* the result of the check. The result is true if the specified version of the
* extension is supported, and false otherwise.
*
* @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 extension is not a valid
* extension, or @p result is NULL.
*/
hsa_status_t HSA_API
hsa_agent_extension_supported(uint16_t extension, hsa_agent_t agent,
uint16_t version_major,
uint16_t version_minor, bool *result);
/** @} */
/** \defgroup signals Signals
* @{
*/
/**
* @brief Signal handle.
*/
typedef struct hsa_signal_s {
/**
* Opaque handle. The value 0 is reserved.
*/
uint64_t handle;
} hsa_signal_t;
/**
* @brief Signal value. The value occupies 32 bits in small machine mode, and 64
* bits in large machine mode.
*/
#ifdef HSA_LARGE_MODEL
typedef int64_t hsa_signal_value_t;
#else
typedef int32_t hsa_signal_value_t;
#endif
/**
* @brief Create a signal.
*
* @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[out] signal Pointer to a memory location where the HSA runtime will
* store the newly created signal handle.
*
* @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 There is failure to allocate the
* resources required by the implementation.
*
* @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_signal_create(hsa_signal_value_t initial_value, uint32_t num_consumers,
const hsa_agent_t *consumers, hsa_signal_t *signal);
/**
* @brief Destroy a signal previous created by ::hsa_signal_create.
*
* @param[in] signal Signal.
*
* @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 @p signal is invalid.
*
* @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT The handle in @p signal is 0.
*/
hsa_status_t HSA_API hsa_signal_destroy(hsa_signal_t signal);
/**
* @brief Atomically read the current value of a signal.
*
* @param[in] signal Signal.
*
* @return Value of the signal.
*/
hsa_signal_value_t HSA_API hsa_signal_load_acquire(hsa_signal_t signal);
/**
* @copydoc hsa_signal_load_acquire
*/
hsa_signal_value_t HSA_API hsa_signal_load_relaxed(hsa_signal_t signal);
/**
* @brief Atomically set the value of a signal.
*
* @details If the value of the signal is changed, all the agents waiting
* on @p signal for which @p value satisfies their wait condition are awakened.
*
* @param[in] signal Signal.
*
* @param[in] value New signal value.
*/
void HSA_API
hsa_signal_store_relaxed(hsa_signal_t signal, hsa_signal_value_t value);
/**
* @copydoc hsa_signal_store_relaxed
*/
void HSA_API
hsa_signal_store_release(hsa_signal_t signal, hsa_signal_value_t value);
/**
* @brief Atomically set the value of a signal and return its previous value.
*
* @details If the value of the signal is changed, all the agents waiting
* on @p signal for which @p value satisfies their wait condition are awakened.
*
* @param[in] signal Signal. If @p signal is a queue doorbell signal, the