hsa_ext_amd.h 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2014-2020 Advanced Micro Devices Inc. All rights reserved.
  4. //
  5. // Permission is hereby granted, free of charge, to any person or organization
  6. // obtaining a copy of the software and accompanying documentation covered by
  7. // this license (the "Software") to use, reproduce, display, distribute,
  8. // execute, and transmit the Software, and to prepare derivative works of the
  9. // Software, and to permit third-parties to whom the Software is furnished to
  10. // do so, all subject to the following:
  11. //
  12. // The copyright notices in the Software and this entire statement, including
  13. // the above license grant, this restriction and the following disclaimer,
  14. // must be included in all copies of the Software, in whole or in part, and
  15. // all derivative works of the Software, unless such copies or derivative
  16. // works are solely in the form of machine-executable object code generated by
  17. // a source language processor.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  22. // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  23. // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  24. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25. // DEALINGS IN THE SOFTWARE.
  26. //
  27. ////////////////////////////////////////////////////////////////////////////////
  28. // HSA AMD extension.
  29. #ifndef HSA_RUNTIME_EXT_AMD_H_
  30. #define HSA_RUNTIME_EXT_AMD_H_
  31. #include "hsa.h"
  32. #include "hsa_ext_image.h"
  33. #define HSA_AMD_INTERFACE_VERSION_MAJOR 1
  34. #define HSA_AMD_INTERFACE_VERSION_MINOR 0
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /**
  39. * @brief Enumeration constants added to ::hsa_status_t.
  40. *
  41. * @remark Additions to hsa_status_t
  42. */
  43. enum {
  44. /**
  45. * The memory pool is invalid.
  46. */
  47. HSA_STATUS_ERROR_INVALID_MEMORY_POOL = 40,
  48. /**
  49. * Agent accessed memory beyond the maximum legal address.
  50. */
  51. HSA_STATUS_ERROR_MEMORY_APERTURE_VIOLATION = 41,
  52. /**
  53. * Agent executed an invalid shader instruction.
  54. */
  55. HSA_STATUS_ERROR_ILLEGAL_INSTRUCTION = 42,
  56. };
  57. /**
  58. * @brief Agent attributes.
  59. */
  60. typedef enum hsa_amd_agent_info_s {
  61. /**
  62. * Chip identifier. The type of this attribute is uint32_t.
  63. */
  64. HSA_AMD_AGENT_INFO_CHIP_ID = 0xA000,
  65. /**
  66. * Size of a cacheline in bytes. The type of this attribute is uint32_t.
  67. */
  68. HSA_AMD_AGENT_INFO_CACHELINE_SIZE = 0xA001,
  69. /**
  70. * The number of compute unit available in the agent. The type of this
  71. * attribute is uint32_t.
  72. */
  73. HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT = 0xA002,
  74. /**
  75. * The maximum clock frequency of the agent in MHz. The type of this
  76. * attribute is uint32_t.
  77. */
  78. HSA_AMD_AGENT_INFO_MAX_CLOCK_FREQUENCY = 0xA003,
  79. /**
  80. * Internal driver node identifier. The type of this attribute is uint32_t.
  81. */
  82. HSA_AMD_AGENT_INFO_DRIVER_NODE_ID = 0xA004,
  83. /**
  84. * Max number of watch points on memory address ranges to generate exception
  85. * events when the watched addresses are accessed. The type of this
  86. * attribute is uint32_t.
  87. */
  88. HSA_AMD_AGENT_INFO_MAX_ADDRESS_WATCH_POINTS = 0xA005,
  89. /**
  90. * Agent BDF_ID, named LocationID in thunk. The type of this attribute is
  91. * uint32_t.
  92. */
  93. HSA_AMD_AGENT_INFO_BDFID = 0xA006,
  94. /**
  95. * Memory Interface width, the return value type is uint32_t.
  96. * This attribute is deprecated.
  97. */
  98. HSA_AMD_AGENT_INFO_MEMORY_WIDTH = 0xA007,
  99. /**
  100. * Max Memory Clock, the return value type is uint32_t.
  101. */
  102. HSA_AMD_AGENT_INFO_MEMORY_MAX_FREQUENCY = 0xA008,
  103. /**
  104. * Board name of Agent - populated from MarketingName of Kfd Node
  105. * The value is an Ascii string of 64 chars.
  106. */
  107. HSA_AMD_AGENT_INFO_PRODUCT_NAME = 0xA009,
  108. /**
  109. * Maximum number of waves possible in a Compute Unit.
  110. * The type of this attribute is uint32_t.
  111. */
  112. HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU = 0xA00A,
  113. /**
  114. * Number of SIMD's per compute unit CU
  115. * The type of this attribute is uint32_t.
  116. */
  117. HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU = 0xA00B,
  118. /**
  119. * Number of Shader Engines (SE) in Gpu
  120. * The type of this attribute is uint32_t.
  121. */
  122. HSA_AMD_AGENT_INFO_NUM_SHADER_ENGINES = 0xA00C,
  123. /**
  124. * Number of Shader Arrays Per Shader Engines in Gpu
  125. * The type of this attribute is uint32_t.
  126. */
  127. HSA_AMD_AGENT_INFO_NUM_SHADER_ARRAYS_PER_SE = 0xA00D,
  128. /**
  129. * Address of the HDP flush registers. Use of these registers does not conform to the HSA memory
  130. * model and should be treated with caution.
  131. * The type of this attribute is hsa_amd_hdp_flush_t.
  132. */
  133. HSA_AMD_AGENT_INFO_HDP_FLUSH = 0xA00E,
  134. /**
  135. * PCIe domain for the agent. Pairs with HSA_AMD_AGENT_INFO_BDFID
  136. * to give the full physical location of the Agent.
  137. * The type of this attribute is uint32_t.
  138. */
  139. HSA_AMD_AGENT_INFO_DOMAIN = 0xA00F,
  140. /**
  141. * Queries for support of cooperative queues. See ::HSA_QUEUE_TYPE_COOPERATIVE.
  142. * The type of this attribute is bool.
  143. */
  144. HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES = 0xA010,
  145. /**
  146. * Queries UUID of an agent. The value is an Ascii string with a maximum
  147. * of 21 chars including NUL. The string value consists of two parts: header
  148. * and body. The header identifies device type (GPU, CPU, DSP) while body
  149. * encodes UUID as a 16 digit hex string
  150. *
  151. * Agents that do not support UUID will return the string "GPU-XX" or
  152. * "CPU-XX" or "DSP-XX" depending upon their device type ::hsa_device_type_t
  153. */
  154. HSA_AMD_AGENT_INFO_UUID = 0xA011,
  155. /**
  156. * Queries for the ASIC revision of an agent. The value is an integer that
  157. * increments for each revision. This can be used by user-level software to
  158. * change how it operates, depending on the hardware version. This allows
  159. * selective workarounds for hardware errata.
  160. * The type of this attribute is uint32_t.
  161. */
  162. HSA_AMD_AGENT_INFO_ASIC_REVISION = 0xA012
  163. } hsa_amd_agent_info_t;
  164. typedef struct hsa_amd_hdp_flush_s {
  165. uint32_t* HDP_MEM_FLUSH_CNTL;
  166. uint32_t* HDP_REG_FLUSH_CNTL;
  167. } hsa_amd_hdp_flush_t;
  168. /**
  169. * @brief Region attributes.
  170. */
  171. typedef enum hsa_amd_region_info_s {
  172. /**
  173. * Determine if host can access the region. The type of this attribute
  174. * is bool.
  175. */
  176. HSA_AMD_REGION_INFO_HOST_ACCESSIBLE = 0xA000,
  177. /**
  178. * Base address of the region in flat address space.
  179. */
  180. HSA_AMD_REGION_INFO_BASE = 0xA001,
  181. /**
  182. * Memory Interface width, the return value type is uint32_t.
  183. * This attribute is deprecated. Use HSA_AMD_AGENT_INFO_MEMORY_WIDTH.
  184. */
  185. HSA_AMD_REGION_INFO_BUS_WIDTH = 0xA002,
  186. /**
  187. * Max Memory Clock, the return value type is uint32_t.
  188. * This attribute is deprecated. Use HSA_AMD_AGENT_INFO_MEMORY_MAX_FREQUENCY.
  189. */
  190. HSA_AMD_REGION_INFO_MAX_CLOCK_FREQUENCY = 0xA003
  191. } hsa_amd_region_info_t;
  192. /**
  193. * @brief Coherency attributes of fine grain region.
  194. */
  195. typedef enum hsa_amd_coherency_type_s {
  196. /**
  197. * Coherent region.
  198. */
  199. HSA_AMD_COHERENCY_TYPE_COHERENT = 0,
  200. /**
  201. * Non coherent region.
  202. */
  203. HSA_AMD_COHERENCY_TYPE_NONCOHERENT = 1
  204. } hsa_amd_coherency_type_t;
  205. /**
  206. * @brief Get the coherency type of the fine grain region of an agent.
  207. *
  208. * @param[in] agent A valid agent.
  209. *
  210. * @param[out] type Pointer to a memory location where the HSA runtime will
  211. * store the coherency type of the fine grain region.
  212. *
  213. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  214. *
  215. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  216. * initialized.
  217. *
  218. * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
  219. *
  220. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p type is NULL.
  221. */
  222. hsa_status_t HSA_API hsa_amd_coherency_get_type(hsa_agent_t agent,
  223. hsa_amd_coherency_type_t* type);
  224. /**
  225. * @brief Set the coherency type of the fine grain region of an agent.
  226. * Deprecated. This is supported on KV platforms. For backward compatibility
  227. * other platforms will spuriously succeed.
  228. *
  229. * @param[in] agent A valid agent.
  230. *
  231. * @param[in] type The coherency type to be set.
  232. *
  233. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  234. *
  235. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  236. * initialized.
  237. *
  238. * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
  239. *
  240. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p type is invalid.
  241. */
  242. hsa_status_t HSA_API hsa_amd_coherency_set_type(hsa_agent_t agent,
  243. hsa_amd_coherency_type_t type);
  244. /**
  245. * @brief Structure containing profiling dispatch time information.
  246. *
  247. * Times are reported as ticks in the domain of the HSA system clock.
  248. * The HSA system clock tick and frequency is obtained via hsa_system_get_info.
  249. */
  250. typedef struct hsa_amd_profiling_dispatch_time_s {
  251. /**
  252. * Dispatch packet processing start time.
  253. */
  254. uint64_t start;
  255. /**
  256. * Dispatch packet completion time.
  257. */
  258. uint64_t end;
  259. } hsa_amd_profiling_dispatch_time_t;
  260. /**
  261. * @brief Structure containing profiling async copy time information.
  262. *
  263. * Times are reported as ticks in the domain of the HSA system clock.
  264. * The HSA system clock tick and frequency is obtained via hsa_system_get_info.
  265. */
  266. typedef struct hsa_amd_profiling_async_copy_time_s {
  267. /**
  268. * Async copy processing start time.
  269. */
  270. uint64_t start;
  271. /**
  272. * Async copy completion time.
  273. */
  274. uint64_t end;
  275. } hsa_amd_profiling_async_copy_time_t;
  276. /**
  277. * @brief Enable or disable profiling capability of a queue.
  278. *
  279. * @param[in] queue A valid queue.
  280. *
  281. * @param[in] enable 1 to enable profiling. 0 to disable profiling.
  282. *
  283. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  284. *
  285. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  286. * initialized.
  287. *
  288. * @retval ::HSA_STATUS_ERROR_INVALID_QUEUE The queue is invalid.
  289. *
  290. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p queue is NULL.
  291. */
  292. hsa_status_t HSA_API
  293. hsa_amd_profiling_set_profiler_enabled(hsa_queue_t* queue, int enable);
  294. /**
  295. * @brief Enable or disable asynchronous memory copy profiling.
  296. *
  297. * @details The runtime will provide the copy processing start timestamp and
  298. * completion timestamp of each call to hsa_amd_memory_async_copy if the
  299. * async copy profiling is enabled prior to the call to
  300. * hsa_amd_memory_async_copy. The completion signal object is used to
  301. * hold the last async copy start and end timestamp. The client can retrieve
  302. * these timestamps via call to hsa_amd_profiling_get_async_copy_time.
  303. *
  304. * @param[in] enable True to enable profiling. False to disable profiling.
  305. *
  306. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  307. *
  308. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  309. * initialized.
  310. *
  311. * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES Failed on allocating resources
  312. * needed to profile the asynchronous copy.
  313. */
  314. hsa_status_t HSA_API
  315. hsa_amd_profiling_async_copy_enable(bool enable);
  316. /**
  317. * @brief Retrieve packet processing time stamps.
  318. *
  319. * @param[in] agent The agent with which the signal was last used. For
  320. * instance, if the profiled dispatch packet is dispatched onto queue Q,
  321. * which was created on agent A, then this parameter must be A.
  322. *
  323. * @param[in] signal A signal used as the completion signal of the dispatch
  324. * packet to retrieve time stamps from. This dispatch packet must have been
  325. * issued to a queue with profiling enabled and have already completed. Also
  326. * the signal must not have yet been used in any other packet following the
  327. * completion of the profiled dispatch packet.
  328. *
  329. * @param[out] time Packet processing timestamps in the HSA system clock
  330. * domain.
  331. *
  332. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  333. *
  334. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  335. * initialized.
  336. *
  337. * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
  338. *
  339. * @retval ::HSA_STATUS_ERROR_INVALID_SIGNAL The signal is invalid.
  340. *
  341. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p time is NULL.
  342. */
  343. hsa_status_t HSA_API hsa_amd_profiling_get_dispatch_time(
  344. hsa_agent_t agent, hsa_signal_t signal,
  345. hsa_amd_profiling_dispatch_time_t* time);
  346. /**
  347. * @brief Retrieve asynchronous copy timestamps.
  348. *
  349. * @details Async copy profiling is enabled via call to
  350. * hsa_amd_profiling_async_copy_enable.
  351. *
  352. * @param[in] signal A signal used as the completion signal of the call to
  353. * hsa_amd_memory_async_copy.
  354. *
  355. * @param[out] time Async copy processing timestamps in the HSA system clock
  356. * domain.
  357. *
  358. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  359. *
  360. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  361. * initialized.
  362. *
  363. * @retval ::HSA_STATUS_ERROR_INVALID_SIGNAL The signal is invalid.
  364. *
  365. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p time is NULL.
  366. */
  367. hsa_status_t HSA_API hsa_amd_profiling_get_async_copy_time(
  368. hsa_signal_t signal, hsa_amd_profiling_async_copy_time_t* time);
  369. /**
  370. * @brief Computes the frequency ratio and offset between the agent clock and
  371. * HSA system clock and converts the agent's tick to HSA system domain tick.
  372. *
  373. * @param[in] agent The agent used to retrieve the agent_tick. It is user's
  374. * responsibility to make sure the tick number is from this agent, otherwise,
  375. * the behavior is undefined.
  376. *
  377. * @param[in] agent_tick The tick count retrieved from the specified @p agent.
  378. *
  379. * @param[out] system_tick The translated HSA system domain clock counter tick.
  380. *
  381. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  382. *
  383. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  384. * initialized.
  385. *
  386. * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
  387. *
  388. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p system_tick is NULL;
  389. */
  390. hsa_status_t HSA_API
  391. hsa_amd_profiling_convert_tick_to_system_domain(hsa_agent_t agent,
  392. uint64_t agent_tick,
  393. uint64_t* system_tick);
  394. /**
  395. * @brief Signal attribute flags.
  396. */
  397. typedef enum {
  398. /**
  399. * Signal will only be consumed by AMD GPUs. Limits signal consumption to
  400. * AMD GPU agents only. Ignored if @p num_consumers is not zero (all agents).
  401. */
  402. HSA_AMD_SIGNAL_AMD_GPU_ONLY = 1,
  403. /**
  404. * Signal may be used for interprocess communication.
  405. * IPC signals can be read, written, and waited on from any process.
  406. * Profiling using an IPC enabled signal is only supported in a single process
  407. * at a time. Producing profiling data in one process and consuming it in
  408. * another process is undefined.
  409. */
  410. HSA_AMD_SIGNAL_IPC = 2,
  411. } hsa_amd_signal_attribute_t;
  412. /**
  413. * @brief Create a signal with specific attributes.
  414. *
  415. * @param[in] initial_value Initial value of the signal.
  416. *
  417. * @param[in] num_consumers Size of @p consumers. A value of 0 indicates that
  418. * any agent might wait on the signal.
  419. *
  420. * @param[in] consumers List of agents that might consume (wait on) the
  421. * signal. If @p num_consumers is 0, this argument is ignored; otherwise, the
  422. * HSA runtime might use the list to optimize the handling of the signal
  423. * object. If an agent not listed in @p consumers waits on the returned
  424. * signal, the behavior is undefined. The memory associated with @p consumers
  425. * can be reused or freed after the function returns.
  426. *
  427. * @param[in] attributes Requested signal attributes. Multiple signal attributes
  428. * may be requested by combining them with bitwise OR. Requesting no attributes
  429. * (@p attributes == 0) results in the same signal as would have been obtained
  430. * via hsa_signal_create.
  431. *
  432. * @param[out] signal Pointer to a memory location where the HSA runtime will
  433. * store the newly created signal handle. Must not be NULL.
  434. *
  435. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  436. *
  437. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  438. * initialized.
  439. *
  440. * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to allocate
  441. * the required resources.
  442. *
  443. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p signal is NULL, @p
  444. * num_consumers is greater than 0 but @p consumers is NULL, or @p consumers
  445. * contains duplicates.
  446. */
  447. hsa_status_t HSA_API hsa_amd_signal_create(hsa_signal_value_t initial_value, uint32_t num_consumers,
  448. const hsa_agent_t* consumers, uint64_t attributes,
  449. hsa_signal_t* signal);
  450. /**
  451. * @brief Asyncronous signal handler function type.
  452. *
  453. * @details Type definition of callback function to be used with
  454. * hsa_amd_signal_async_handler. This callback is invoked if the associated
  455. * signal and condition are met. The callback receives the value of the signal
  456. * which satisfied the associated wait condition and a user provided value. If
  457. * the callback returns true then the callback will be called again if the
  458. * associated signal and condition are satisfied again. If the callback returns
  459. * false then it will not be called again.
  460. *
  461. * @param[in] value Contains the value of the signal observed by
  462. * hsa_amd_signal_async_handler which caused the signal handler to be invoked.
  463. *
  464. * @param[in] arg Contains the user provided value given when the signal handler
  465. * was registered with hsa_amd_signal_async_handler
  466. *
  467. * @retval true resumes monitoring the signal with this handler (as if calling
  468. * hsa_amd_signal_async_handler again with identical parameters)
  469. *
  470. * @retval false stops monitoring the signal with this handler (handler will
  471. * not be called again for this signal)
  472. *
  473. */
  474. typedef bool (*hsa_amd_signal_handler)(hsa_signal_value_t value, void* arg);
  475. /**
  476. * @brief Register asynchronous signal handler function.
  477. *
  478. * @details Allows registering a callback function and user provided value with
  479. * a signal and wait condition. The callback will be invoked if the associated
  480. * signal and wait condition are satisfied. Callbacks will be invoked serially
  481. * but in an arbitrary order so callbacks should be independent of each other.
  482. * After being invoked a callback may continue to wait for its associated signal
  483. * and condition and, possibly, be invoked again. Or the callback may stop
  484. * waiting. If the callback returns true then it will continue waiting and may
  485. * be called again. If false then the callback will not wait again and will not
  486. * be called again for the associated signal and condition. It is possible to
  487. * register the same callback multiple times with the same or different signals
  488. * and/or conditions. Each registration of the callback will be treated entirely
  489. * independently.
  490. *
  491. * @param[in] signal hsa signal to be asynchronously monitored
  492. *
  493. * @param[in] cond condition value to monitor for
  494. *
  495. * @param[in] value signal value used in condition expression
  496. *
  497. * @param[in] handler asynchronous signal handler invoked when signal's
  498. * condition is met
  499. *
  500. * @param[in] arg user provided value which is provided to handler when handler
  501. * is invoked
  502. *
  503. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  504. *
  505. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  506. * initialized.
  507. *
  508. * @retval ::HSA_STATUS_ERROR_INVALID_SIGNAL signal is not a valid hsa_signal_t
  509. *
  510. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT handler is invalid (NULL)
  511. *
  512. * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime is out of
  513. * resources or blocking signals are not supported by the HSA driver component.
  514. *
  515. */
  516. hsa_status_t HSA_API
  517. hsa_amd_signal_async_handler(hsa_signal_t signal,
  518. hsa_signal_condition_t cond,
  519. hsa_signal_value_t value,
  520. hsa_amd_signal_handler handler, void* arg);
  521. /**
  522. * @brief Call a function asynchronously
  523. *
  524. * @details Provides access to the runtime's asynchronous event handling thread
  525. * for general asynchronous functions. Functions queued this way are executed
  526. * in the same manner as if they were a signal handler who's signal is
  527. * satisfied.
  528. *
  529. * @param[in] callback asynchronous function to be invoked
  530. *
  531. * @param[in] arg user provided value which is provided to handler when handler
  532. * is invoked
  533. *
  534. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  535. *
  536. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  537. * initialized.
  538. *
  539. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT handler is invalid (NULL)
  540. *
  541. * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime is out of
  542. * resources or blocking signals are not supported by the HSA driver component.
  543. *
  544. */
  545. hsa_status_t HSA_API
  546. hsa_amd_async_function(void (*callback)(void* arg), void* arg);
  547. /**
  548. * @brief Wait for any signal-condition pair to be satisfied.
  549. *
  550. * @details Allows waiting for any of several signal and conditions pairs to be
  551. * satisfied. The function returns the index into the list of signals of the
  552. * first satisfying signal-condition pair. The value of the satisfying signal's
  553. * value is returned in satisfying_value unless satisfying_value is NULL. This
  554. * function provides only relaxed memory semantics.
  555. */
  556. uint32_t HSA_API
  557. hsa_amd_signal_wait_any(uint32_t signal_count, hsa_signal_t* signals,
  558. hsa_signal_condition_t* conds,
  559. hsa_signal_value_t* values, uint64_t timeout_hint,
  560. hsa_wait_state_t wait_hint,
  561. hsa_signal_value_t* satisfying_value);
  562. /**
  563. * @brief Query image limits.
  564. *
  565. * @param[in] agent A valid agent.
  566. *
  567. * @param[in] attribute HSA image info attribute to query.
  568. *
  569. * @param[out] value Pointer to an application-allocated buffer where to store
  570. * the value of the attribute. If the buffer passed by the application is not
  571. * large enough to hold the value of @p attribute, the behavior is undefined.
  572. *
  573. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  574. *
  575. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  576. * initialized.
  577. *
  578. * @retval ::HSA_STATUS_ERROR_INVALID_QUEUE @p value is NULL or @p attribute <
  579. * HSA_EXT_AGENT_INFO_IMAGE_1D_MAX_ELEMENTS or @p attribute >
  580. * HSA_EXT_AGENT_INFO_IMAGE_ARRAY_MAX_LAYERS.
  581. *
  582. */
  583. hsa_status_t HSA_API hsa_amd_image_get_info_max_dim(hsa_agent_t agent,
  584. hsa_agent_info_t attribute,
  585. void* value);
  586. /**
  587. * @brief Set a CU affinity to specific queues within the process, this function
  588. * call is "atomic".
  589. *
  590. * @param[in] queue A pointer to HSA queue.
  591. *
  592. * @param[in] num_cu_mask_count Size of CUMask bit array passed in.
  593. *
  594. * @param[in] cu_mask Bit-vector representing the CU mask.
  595. *
  596. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  597. *
  598. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  599. * initialized.
  600. *
  601. * @retval ::HSA_STATUS_ERROR_INVALID_QUEUE @p queue is NULL or invalid.
  602. *
  603. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p num_cu_mask_count is not
  604. * multiple of 32 or @p cu_mask is NULL.
  605. *
  606. * @retval ::HSA_STATUS_ERROR failed to call thunk api
  607. *
  608. */
  609. hsa_status_t HSA_API hsa_amd_queue_cu_set_mask(const hsa_queue_t* queue,
  610. uint32_t num_cu_mask_count,
  611. const uint32_t* cu_mask);
  612. /**
  613. * @brief Memory segments associated with a memory pool.
  614. */
  615. typedef enum {
  616. /**
  617. * Global segment. Used to hold data that is shared by all agents.
  618. */
  619. HSA_AMD_SEGMENT_GLOBAL = 0,
  620. /**
  621. * Read-only segment. Used to hold data that remains constant during the
  622. * execution of a kernel.
  623. */
  624. HSA_AMD_SEGMENT_READONLY = 1,
  625. /**
  626. * Private segment. Used to hold data that is local to a single work-item.
  627. */
  628. HSA_AMD_SEGMENT_PRIVATE = 2,
  629. /**
  630. * Group segment. Used to hold data that is shared by the work-items of a
  631. * work-group.
  632. */
  633. HSA_AMD_SEGMENT_GROUP = 3,
  634. } hsa_amd_segment_t;
  635. /**
  636. * @brief A memory pool encapsulates physical storage on an agent
  637. * along with a memory access model.
  638. *
  639. * @details A memory pool encapsulates a physical partition of an agent's
  640. * memory system along with a memory access model. Division of a single
  641. * memory system into separate pools allows querying each partition's access
  642. * path properties (see ::hsa_amd_agent_memory_pool_get_info). Allocations
  643. * from a pool are preferentially bound to that pool's physical partition.
  644. * Binding to the pool's preferential physical partition may not be
  645. * possible or persistent depending on the system's memory policy
  646. * and/or state which is beyond the scope of HSA APIs.
  647. *
  648. * For example, a multi-node NUMA memory system may be represented by multiple
  649. * pool's with each pool providing size and access path information for the
  650. * partition it represents. Allocations from a pool are preferentially bound
  651. * to the pool's partition (which in this example is a NUMA node) while
  652. * following its memory access model. The actual placement may vary or migrate
  653. * due to the system's NUMA policy and state, which is beyond the scope of
  654. * HSA APIs.
  655. */
  656. typedef struct hsa_amd_memory_pool_s {
  657. /**
  658. * Opaque handle.
  659. */
  660. uint64_t handle;
  661. } hsa_amd_memory_pool_t;
  662. typedef enum hsa_amd_memory_pool_global_flag_s {
  663. /**
  664. * The application can use allocations in the memory pool to store kernel
  665. * arguments, and provide the values for the kernarg segment of
  666. * a kernel dispatch.
  667. */
  668. HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT = 1,
  669. /**
  670. * Updates to memory in this pool conform to HSA memory consistency model.
  671. * If this flag is set, then ::HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_COARSE_GRAINED
  672. * must not be set.
  673. */
  674. HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_FINE_GRAINED = 2,
  675. /**
  676. * Writes to memory in this pool can be performed by a single agent at a time.
  677. */
  678. HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_COARSE_GRAINED = 4
  679. } hsa_amd_memory_pool_global_flag_t;
  680. /**
  681. * @brief Memory pool features.
  682. */
  683. typedef enum {
  684. /**
  685. * Segment where the memory pool resides. The type of this attribute is
  686. * ::hsa_amd_segment_t.
  687. */
  688. HSA_AMD_MEMORY_POOL_INFO_SEGMENT = 0,
  689. /**
  690. * Flag mask. The value of this attribute is undefined if the value of
  691. * ::HSA_AMD_MEMORY_POOL_INFO_SEGMENT is not ::HSA_AMD_SEGMENT_GLOBAL. The type
  692. * of
  693. * this attribute is uint32_t, a bit-field of
  694. * ::hsa_amd_memory_pool_global_flag_t
  695. * values.
  696. */
  697. HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS = 1,
  698. /**
  699. * Size of this pool, in bytes. The type of this attribute is size_t.
  700. */
  701. HSA_AMD_MEMORY_POOL_INFO_SIZE = 2,
  702. /**
  703. * Indicates whether memory in this pool can be allocated using
  704. * ::hsa_amd_memory_pool_allocate. The type of this attribute is bool.
  705. *
  706. * The value of this flag is always false for memory pools in the group and
  707. * private segments.
  708. */
  709. HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED = 5,
  710. /**
  711. * Allocation granularity of buffers allocated by
  712. * ::hsa_amd_memory_pool_allocate
  713. * in this memory pool. The size of a buffer allocated in this pool is a
  714. * multiple of the value of this attribute. The value of this attribute is
  715. * only defined if ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED is true for
  716. * this pool. The type of this attribute is size_t.
  717. */
  718. HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_GRANULE = 6,
  719. /**
  720. * Alignment of buffers allocated by ::hsa_amd_memory_pool_allocate in this
  721. * pool. The value of this attribute is only defined if
  722. * ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED is true for this pool, and
  723. * must be a power of 2. The type of this attribute is size_t.
  724. */
  725. HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALIGNMENT = 7,
  726. /**
  727. * This memory_pool can be made directly accessible by all the agents in the
  728. * system (::hsa_amd_agent_memory_pool_get_info does not return
  729. * ::HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED for any agent). The type of this
  730. * attribute is bool.
  731. */
  732. HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL = 15,
  733. /**
  734. * Maximum aggregate allocation size in bytes. The type of this attribute
  735. * is size_t.
  736. */
  737. HSA_AMD_MEMORY_POOL_INFO_ALLOC_MAX_SIZE = 16,
  738. } hsa_amd_memory_pool_info_t;
  739. /**
  740. * @brief Get the current value of an attribute of a memory pool.
  741. *
  742. * @param[in] memory_pool A valid memory pool.
  743. *
  744. * @param[in] attribute Attribute to query.
  745. *
  746. * @param[out] value Pointer to a application-allocated buffer where to store
  747. * the value of the attribute. If the buffer passed by the application is not
  748. * large enough to hold the value of @p attribute, the behavior is undefined.
  749. *
  750. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  751. *
  752. */
  753. hsa_status_t HSA_API
  754. hsa_amd_memory_pool_get_info(hsa_amd_memory_pool_t memory_pool,
  755. hsa_amd_memory_pool_info_t attribute,
  756. void* value);
  757. /**
  758. * @brief Iterate over the memory pools associated with a given agent, and
  759. * invoke an application-defined callback on every iteration.
  760. *
  761. * @details An agent can directly access buffers located in some memory pool, or
  762. * be enabled to access them by the application (see ::hsa_amd_agents_allow_access),
  763. * yet that memory pool may not be returned by this function for that given
  764. * agent.
  765. *
  766. * A memory pool of fine-grained type must be associated only with the host.
  767. *
  768. * @param[in] agent A valid agent.
  769. *
  770. * @param[in] callback Callback to be invoked on the same thread that called
  771. * ::hsa_amd_agent_iterate_memory_pools, serially, once per memory pool that is
  772. * associated with the agent. The HSA runtime passes two arguments to the
  773. * callback: the memory pool, and the application data. If @p callback
  774. * returns a status other than ::HSA_STATUS_SUCCESS for a particular iteration,
  775. * the traversal stops and ::hsa_amd_agent_iterate_memory_pools returns that status
  776. * value.
  777. *
  778. * @param[in] data Application data that is passed to @p callback on every
  779. * iteration. May be NULL.
  780. *
  781. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  782. *
  783. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  784. * initialized.
  785. *
  786. * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
  787. *
  788. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL.
  789. */
  790. hsa_status_t HSA_API hsa_amd_agent_iterate_memory_pools(
  791. hsa_agent_t agent,
  792. hsa_status_t (*callback)(hsa_amd_memory_pool_t memory_pool, void* data),
  793. void* data);
  794. /**
  795. * @brief Allocate a block of memory (or buffer) in the specified pool.
  796. *
  797. * @param[in] memory_pool Memory pool where to allocate memory from. The memory
  798. * pool must have the ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED flag set.
  799. *
  800. * @param[in] size Allocation size, in bytes. Must not be zero. This value is
  801. * rounded up to the nearest multiple of
  802. * ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_GRANULE in @p memory_pool.
  803. *
  804. * @param[in] flags A bit-field that is used to specify allocation
  805. * directives. Reserved parameter, must be 0.
  806. *
  807. * @param[out] ptr Pointer to the location where to store the base virtual
  808. * address of
  809. * the allocated block. The returned base address is aligned to the value of
  810. * ::HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALIGNMENT in @p memory_pool. If the
  811. * allocation fails, the returned value is undefined.
  812. *
  813. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  814. *
  815. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  816. * initialized.
  817. *
  818. * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES No memory is available.
  819. *
  820. * @retval ::HSA_STATUS_ERROR_INVALID_MEMORY_POOL The memory pool is invalid.
  821. *
  822. * @retval ::HSA_STATUS_ERROR_INVALID_ALLOCATION The host is not allowed to
  823. * allocate memory in @p memory_pool, or @p size is greater than
  824. * the value of HSA_AMD_MEMORY_POOL_INFO_ALLOC_MAX_SIZE in @p memory_pool.
  825. *
  826. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p ptr is NULL, or @p size is 0,
  827. * or flags is not 0.
  828. *
  829. */
  830. hsa_status_t HSA_API
  831. hsa_amd_memory_pool_allocate(hsa_amd_memory_pool_t memory_pool, size_t size,
  832. uint32_t flags, void** ptr);
  833. /**
  834. * @brief Deallocate a block of memory previously allocated using
  835. * ::hsa_amd_memory_pool_allocate.
  836. *
  837. * @param[in] ptr Pointer to a memory block. If @p ptr does not match a value
  838. * previously returned by ::hsa_amd_memory_pool_allocate, the behavior is undefined.
  839. *
  840. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  841. *
  842. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  843. * initialized.
  844. *
  845. */
  846. hsa_status_t HSA_API hsa_amd_memory_pool_free(void* ptr);
  847. /**
  848. * @brief Asynchronously copy a block of memory from the location pointed to by
  849. * @p src on the @p src_agent to the memory block pointed to by @p dst on the @p
  850. * dst_agent.
  851. * Because the DMA engines used may not be in the same coherency domain, the caller must ensure
  852. * that buffers are system-level coherent. In general this requires the sending device to have
  853. * released the buffer to system scope prior to executing the copy API and the receiving device
  854. * must execute a system scope acquire fence prior to use of the destination buffer.
  855. *
  856. * @param[out] dst Buffer where the content is to be copied.
  857. *
  858. * @param[in] dst_agent Agent associated with the @p dst. The agent must be able to directly
  859. * access both the source and destination buffers in their current locations.
  860. *
  861. * @param[in] src A valid pointer to the source of data to be copied. The source
  862. * buffer must not overlap with the destination buffer, otherwise the copy will succeed
  863. * but contents of @p dst is undefined.
  864. *
  865. * @param[in] src_agent Agent associated with the @p src. The agent must be able to directly
  866. * access both the source and destination buffers in their current locations.
  867. *
  868. * @param[in] size Number of bytes to copy. If @p size is 0, no copy is
  869. * performed and the function returns success. Copying a number of bytes larger
  870. * than the size of the buffers pointed by @p dst or @p src results in undefined
  871. * behavior.
  872. *
  873. * @param[in] num_dep_signals Number of dependent signals. Can be 0.
  874. *
  875. * @param[in] dep_signals List of signals that must be waited on before the copy
  876. * operation starts. The copy will start after every signal has been observed with
  877. * the value 0. The dependent signal should not include completion signal from hsa_amd_memory_async_copy
  878. * operation to be issued in future as that can result in a deadlock. If @p num_dep_signals is 0, this
  879. * argument is ignored.
  880. *
  881. * @param[in] completion_signal Signal used to indicate completion of the copy
  882. * operation. When the copy operation is finished, the value of the signal is
  883. * decremented. The runtime indicates that an error has occurred during the copy
  884. * operation by setting the value of the completion signal to a negative
  885. * number. The signal handle must not be 0.
  886. *
  887. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. The
  888. * application is responsible for checking for asynchronous error conditions
  889. * (see the description of @p completion_signal).
  890. *
  891. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  892. * initialized.
  893. *
  894. * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid.
  895. *
  896. * @retval ::HSA_STATUS_ERROR_INVALID_SIGNAL @p completion_signal is invalid.
  897. *
  898. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT The source or destination
  899. * pointers are NULL, or the completion signal is 0.
  900. */
  901. hsa_status_t HSA_API
  902. hsa_amd_memory_async_copy(void* dst, hsa_agent_t dst_agent, const void* src,
  903. hsa_agent_t src_agent, size_t size,
  904. uint32_t num_dep_signals,
  905. const hsa_signal_t* dep_signals,
  906. hsa_signal_t completion_signal);
  907. /*
  908. [Provisional API]
  909. Pitched memory descriptor.
  910. All elements must be 4 byte aligned. Pitch and slice are in bytes.
  911. */
  912. typedef struct hsa_pitched_ptr_s {
  913. void* base;
  914. size_t pitch;
  915. size_t slice;
  916. } hsa_pitched_ptr_t;
  917. /*
  918. [Provisional API]
  919. Copy direction flag.
  920. */
  921. typedef enum {
  922. hsaHostToHost = 0,
  923. hsaHostToDevice = 1,
  924. hsaDeviceToHost = 2,
  925. hsaDeviceToDevice = 3
  926. } hsa_amd_copy_direction_t;
  927. /*
  928. [Provisional API]
  929. SDMA 3D memory copy API. The same requirements must be met by src and dst as in
  930. hsa_amd_memory_async_copy.
  931. Both src and dst must be directly accessible to the copy_agent during the copy, src and dst rects
  932. must not overlap.
  933. CPU agents are not supported. API requires SDMA and will return an error if SDMA is not available.
  934. Offsets and range carry x in bytes, y and z in rows and layers.
  935. */
  936. hsa_status_t HSA_API hsa_amd_memory_async_copy_rect(
  937. const hsa_pitched_ptr_t* dst, const hsa_dim3_t* dst_offset, const hsa_pitched_ptr_t* src,
  938. const hsa_dim3_t* src_offset, const hsa_dim3_t* range, hsa_agent_t copy_agent,
  939. hsa_amd_copy_direction_t dir, uint32_t num_dep_signals, const hsa_signal_t* dep_signals,
  940. hsa_signal_t completion_signal);
  941. /**
  942. * @brief Type of accesses to a memory pool from a given agent.
  943. */
  944. typedef enum {
  945. /**
  946. * The agent cannot directly access any buffer in the memory pool.
  947. */
  948. HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED = 0,
  949. /**
  950. * The agent can directly access a buffer located in the pool; the application
  951. * does not need to invoke ::hsa_amd_agents_allow_access.
  952. */
  953. HSA_AMD_MEMORY_POOL_ACCESS_ALLOWED_BY_DEFAULT = 1,
  954. /**
  955. * The agent can directly access a buffer located in the pool, but only if the
  956. * application has previously requested access to that buffer using
  957. * ::hsa_amd_agents_allow_access.
  958. */
  959. HSA_AMD_MEMORY_POOL_ACCESS_DISALLOWED_BY_DEFAULT = 2
  960. } hsa_amd_memory_pool_access_t;
  961. /**
  962. * @brief Properties of the relationship between an agent a memory pool.
  963. */
  964. typedef enum {
  965. /**
  966. * Hyper-transport bus type.
  967. */
  968. HSA_AMD_LINK_INFO_TYPE_HYPERTRANSPORT = 0,
  969. /**
  970. * QPI bus type.
  971. */
  972. HSA_AMD_LINK_INFO_TYPE_QPI = 1,
  973. /**
  974. * PCIe bus type.
  975. */
  976. HSA_AMD_LINK_INFO_TYPE_PCIE = 2,
  977. /**
  978. * Infiniband bus type.
  979. */
  980. HSA_AMD_LINK_INFO_TYPE_INFINBAND = 3,
  981. /**
  982. * xGMI link type.
  983. */
  984. HSA_AMD_LINK_INFO_TYPE_XGMI = 4
  985. } hsa_amd_link_info_type_t;
  986. /**
  987. * @brief Link properties when accessing the memory pool from the specified
  988. * agent.
  989. */
  990. typedef struct hsa_amd_memory_pool_link_info_s {
  991. /**
  992. * Minimum transfer latency (rounded to ns).
  993. */
  994. uint32_t min_latency;
  995. /**
  996. * Maximum transfer latency (rounded to ns).
  997. */
  998. uint32_t max_latency;
  999. /**
  1000. * Minimum link interface bandwidth in MB/s.
  1001. */
  1002. uint32_t min_bandwidth;
  1003. /**
  1004. * Maximum link interface bandwidth in MB/s.
  1005. */
  1006. uint32_t max_bandwidth;
  1007. /**
  1008. * Support for 32-bit atomic transactions.
  1009. */
  1010. bool atomic_support_32bit;
  1011. /**
  1012. * Support for 64-bit atomic transactions.
  1013. */
  1014. bool atomic_support_64bit;
  1015. /**
  1016. * Support for cache coherent transactions.
  1017. */
  1018. bool coherent_support;
  1019. /**
  1020. * The type of bus/link.
  1021. */
  1022. hsa_amd_link_info_type_t link_type;
  1023. /**
  1024. * NUMA distance of memory pool relative to querying agent
  1025. */
  1026. uint32_t numa_distance;
  1027. } hsa_amd_memory_pool_link_info_t;
  1028. /**
  1029. * @brief Properties of the relationship between an agent a memory pool.
  1030. */
  1031. typedef enum {
  1032. /**
  1033. * Access to buffers located in the memory pool. The type of this attribute
  1034. * is ::hsa_amd_memory_pool_access_t.
  1035. *
  1036. * An agent can always directly access buffers currently located in a memory
  1037. * pool that is associated (the memory_pool is one of the values returned by
  1038. * ::hsa_amd_agent_iterate_memory_pools on the agent) with that agent. If the
  1039. * buffer is currently located in a memory pool that is not associated with
  1040. * the agent, and the value returned by this function for the given
  1041. * combination of agent and memory pool is not
  1042. * HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED, the application still needs to invoke
  1043. * ::hsa_amd_agents_allow_access in order to gain direct access to the buffer.
  1044. *
  1045. * If the given agent can directly access buffers the pool, the result is not
  1046. * HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED. If the memory pool is associated with
  1047. * the agent, or it is of fined-grained type, the result must not be
  1048. * HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED. If the memory pool is not associated
  1049. * with the agent, and does not reside in the global segment, the result must
  1050. * be HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED.
  1051. */
  1052. HSA_AMD_AGENT_MEMORY_POOL_INFO_ACCESS = 0,
  1053. /**
  1054. * Number of links to hop when accessing the memory pool from the specified
  1055. * agent. The value of this attribute is zero if the memory pool is associated
  1056. * with the agent, or if the access type is
  1057. * HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED. The type of this attribute is
  1058. * uint32_t.
  1059. */
  1060. HSA_AMD_AGENT_MEMORY_POOL_INFO_NUM_LINK_HOPS = 1,
  1061. /**
  1062. * Details of each link hop when accessing the memory pool starting from the
  1063. * specified agent. The type of this attribute is an array size of
  1064. * HSA_AMD_AGENT_MEMORY_POOL_INFO_NUM_LINK_HOPS with each element containing
  1065. * ::hsa_amd_memory_pool_link_info_t.
  1066. */
  1067. HSA_AMD_AGENT_MEMORY_POOL_INFO_LINK_INFO = 2
  1068. } hsa_amd_agent_memory_pool_info_t;
  1069. /**
  1070. * @brief Get the current value of an attribute of the relationship between an
  1071. * agent and a memory pool.
  1072. *
  1073. * @param[in] agent Agent.
  1074. *
  1075. * @param[in] memory_pool Memory pool.
  1076. *
  1077. * @param[in] attribute Attribute to query.
  1078. *
  1079. * @param[out] value Pointer to a application-allocated buffer where to store
  1080. * the value of the attribute. If the buffer passed by the application is not
  1081. * large enough to hold the value of @p attribute, the behavior is undefined.
  1082. *
  1083. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  1084. *
  1085. */
  1086. hsa_status_t HSA_API hsa_amd_agent_memory_pool_get_info(
  1087. hsa_agent_t agent, hsa_amd_memory_pool_t memory_pool,
  1088. hsa_amd_agent_memory_pool_info_t attribute, void* value);
  1089. /**
  1090. * @brief Enable direct access to a buffer from a given set of agents.
  1091. *
  1092. * @details
  1093. *
  1094. * Upon return, only the listed agents and the agent associated with the
  1095. * buffer's memory pool have direct access to the @p ptr.
  1096. *
  1097. * Any agent that has access to the buffer before and after the call to
  1098. * ::hsa_amd_agents_allow_access will also have access while
  1099. * ::hsa_amd_agents_allow_access is in progress.
  1100. *
  1101. * The caller is responsible for ensuring that each agent in the list
  1102. * must be able to access the memory pool containing @p ptr
  1103. * (using ::hsa_amd_agent_memory_pool_get_info with ::HSA_AMD_AGENT_MEMORY_POOL_INFO_ACCESS attribute),
  1104. * otherwise error code is returned.
  1105. *
  1106. * @param[in] num_agents Size of @p agents.
  1107. *
  1108. * @param[in] agents List of agents. If @p num_agents is 0, this argument is
  1109. * ignored.
  1110. *
  1111. * @param[in] flags A list of bit-field that is used to specify access
  1112. * information in a per-agent basis. This is currently reserved and must be NULL.
  1113. *
  1114. * @param[in] ptr A buffer previously allocated using ::hsa_amd_memory_pool_allocate.
  1115. *
  1116. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  1117. *
  1118. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  1119. * initialized.
  1120. *
  1121. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p num_agents is 0, or @p agents
  1122. * is NULL, @p flags is not NULL, or attempting to enable access to agent(s)
  1123. * because @p ptr is allocated from an inaccessible pool.
  1124. *
  1125. */
  1126. hsa_status_t HSA_API
  1127. hsa_amd_agents_allow_access(uint32_t num_agents, const hsa_agent_t* agents,
  1128. const uint32_t* flags, const void* ptr);
  1129. /**
  1130. * @brief Query if buffers currently located in some memory pool can be
  1131. * relocated to a destination memory pool.
  1132. *
  1133. * @details If the returned value is non-zero, a migration of a buffer to @p
  1134. * dst_memory_pool using ::hsa_amd_memory_migrate may nevertheless fail due to
  1135. * resource limitations.
  1136. *
  1137. * @param[in] src_memory_pool Source memory pool.
  1138. *
  1139. * @param[in] dst_memory_pool Destination memory pool.
  1140. *
  1141. * @param[out] result Pointer to a memory location where the result of the query
  1142. * is stored. Must not be NULL. If buffers currently located in @p
  1143. * src_memory_pool can be relocated to @p dst_memory_pool, the result is
  1144. * true.
  1145. *
  1146. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  1147. *
  1148. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  1149. * initialized.
  1150. *
  1151. * @retval ::HSA_STATUS_ERROR_INVALID_MEMORY_POOL One of the memory pools is
  1152. * invalid.
  1153. *
  1154. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p result is NULL.
  1155. */
  1156. hsa_status_t HSA_API
  1157. hsa_amd_memory_pool_can_migrate(hsa_amd_memory_pool_t src_memory_pool,
  1158. hsa_amd_memory_pool_t dst_memory_pool,
  1159. bool* result);
  1160. /**
  1161. * @brief Relocate a buffer to a new memory pool.
  1162. *
  1163. * @details When a buffer is migrated, its virtual address remains the same but
  1164. * its physical contents are moved to the indicated memory pool.
  1165. *
  1166. * After migration, only the agent associated with the destination pool will have access.
  1167. *
  1168. * The caller is also responsible for ensuring that the allocation in the
  1169. * source memory pool where the buffer is currently located can be migrated to the
  1170. * specified destination memory pool (using ::hsa_amd_memory_pool_can_migrate returns a value of true
  1171. * for the source and destination memory pools), otherwise behavior is undefined.
  1172. *
  1173. * The caller must ensure that the buffer is not accessed while it is migrated.
  1174. *
  1175. * @param[in] ptr Buffer to be relocated. The buffer must have been released to system
  1176. * prior to call this API. The buffer will be released to system upon completion.
  1177. *
  1178. * @param[in] memory_pool Memory pool where to place the buffer.
  1179. *
  1180. * @param[in] flags A bit-field that is used to specify migration
  1181. * information. Must be zero.
  1182. *
  1183. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  1184. *
  1185. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  1186. * initialized.
  1187. *
  1188. * @retval ::HSA_STATUS_ERROR_INVALID_MEMORY_POOL The destination memory pool is
  1189. * invalid.
  1190. *
  1191. * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES There is a failure in
  1192. * allocating the necessary resources.
  1193. *
  1194. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p flags is not 0.
  1195. */
  1196. hsa_status_t HSA_API hsa_amd_memory_migrate(const void* ptr,
  1197. hsa_amd_memory_pool_t memory_pool,
  1198. uint32_t flags);
  1199. /**
  1200. *
  1201. * @brief Pin a host pointer allocated by C/C++ or OS allocator (i.e. ordinary system DRAM) and
  1202. * return a new pointer accessible by the @p agents. If the @p host_ptr overlaps with previously
  1203. * locked memory, then the overlap area is kept locked (i.e multiple mappings are permitted). In
  1204. * this case, the same input @p host_ptr may give different locked @p agent_ptr and when it does,
  1205. * they are not necessarily coherent (i.e. accessing either @p agent_ptr is not equivalent).
  1206. * Accesses to @p agent_ptr are coarse grained.
  1207. *
  1208. * @param[in] host_ptr A buffer allocated by C/C++ or OS allocator.
  1209. *
  1210. * @param[in] size The size to be locked.
  1211. *
  1212. * @param[in] agents Array of agent handle to gain access to the @p host_ptr.
  1213. * If this parameter is NULL and the @p num_agent is 0, all agents
  1214. * in the platform will gain access to the @p host_ptr.
  1215. *
  1216. * @param[out] agent_ptr Pointer to the location where to store the new address.
  1217. *
  1218. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  1219. *
  1220. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  1221. * initialized.
  1222. *
  1223. * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES There is a failure in
  1224. * allocating the necessary resources.
  1225. *
  1226. * @retval ::HSA_STATUS_ERROR_INVALID_AGENT One or more agent in @p agents is
  1227. * invalid.
  1228. *
  1229. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p size is 0 or @p host_ptr or
  1230. * @p agent_ptr is NULL or @p agents not NULL but @p num_agent is 0 or @p agents
  1231. * is NULL but @p num_agent is not 0.
  1232. */
  1233. hsa_status_t HSA_API hsa_amd_memory_lock(void* host_ptr, size_t size,
  1234. hsa_agent_t* agents, int num_agent,
  1235. void** agent_ptr);
  1236. /**
  1237. *
  1238. * @brief Pin a host pointer allocated by C/C++ or OS allocator (i.e. ordinary system DRAM) and
  1239. * return a new pointer accessible by the @p agents. If the @p host_ptr overlaps with previously
  1240. * locked memory, then the overlap area is kept locked (i.e. multiple mappings are permitted).
  1241. * In this case, the same input @p host_ptr may give different locked @p agent_ptr and when it
  1242. * does, they are not necessarily coherent (i.e. accessing either @p agent_ptr is not equivalent).
  1243. * Acesses to the memory via @p agent_ptr have the same access properties as memory allocated from
  1244. * @p pool as determined by ::hsa_amd_memory_pool_get_info and ::hsa_amd_agent_memory_pool_get_info
  1245. * (ex. coarse/fine grain, platform atomic support, link info). Physical composition and placement
  1246. * of the memory (ex. page size, NUMA binding) is not changed.
  1247. *
  1248. * @param[in] host_ptr A buffer allocated by C/C++ or OS allocator.
  1249. *
  1250. * @param[in] size The size to be locked.
  1251. *
  1252. * @param[in] agents Array of agent handle to gain access to the @p host_ptr.
  1253. * If this parameter is NULL and the @p num_agent is 0, all agents
  1254. * in the platform will gain access to the @p host_ptr.
  1255. *
  1256. * @param[in] pool Global memory pool owned by a CPU agent.
  1257. *
  1258. * @param[in] flags A bit-field that is used to specify allocation
  1259. * directives. Reserved parameter, must be 0.
  1260. *
  1261. * @param[out] agent_ptr Pointer to the location where to store the new address.
  1262. *
  1263. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  1264. *
  1265. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  1266. * initialized.
  1267. *
  1268. * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES There is a failure in
  1269. * allocating the necessary resources.
  1270. *
  1271. * @retval ::HSA_STATUS_ERROR_INVALID_AGENT One or more agent in @p agents is
  1272. * invalid or can not access @p pool.
  1273. *
  1274. * @retval ::HSA_STATUS_ERROR_INVALID_MEMORY_POOL @p pool is invalid or not owned
  1275. * by a CPU agent.
  1276. *
  1277. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p size is 0 or @p host_ptr or
  1278. * @p agent_ptr is NULL or @p agents not NULL but @p num_agent is 0 or @p agents
  1279. * is NULL but @p num_agent is not 0 or flags is not 0.
  1280. */
  1281. hsa_status_t HSA_API hsa_amd_memory_lock_to_pool(void* host_ptr, size_t size, hsa_agent_t* agents,
  1282. int num_agent, hsa_amd_memory_pool_t pool,
  1283. uint32_t flags, void** agent_ptr);
  1284. /**
  1285. *
  1286. * @brief Unpin the host pointer previously pinned via ::hsa_amd_memory_lock or
  1287. * ::hsa_amd_memory_lock_to_pool.
  1288. *
  1289. * @details The behavior is undefined if the host pointer being unpinned does not
  1290. * match previous pinned address or if the host pointer was already deallocated.
  1291. *
  1292. * @param[in] host_ptr A buffer allocated by C/C++ or OS allocator that was
  1293. * pinned previously via ::hsa_amd_memory_lock or ::hsa_amd_memory_lock_to_pool.
  1294. *
  1295. * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully.
  1296. *
  1297. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  1298. * initialized.
  1299. */
  1300. hsa_status_t HSA_API hsa_amd_memory_unlock(void* host_ptr);
  1301. /**
  1302. * @brief Sets the first @p count of uint32_t of the block of memory pointed by
  1303. * @p ptr to the specified @p value.
  1304. *
  1305. * @param[in] ptr Pointer to the block of memory to fill.
  1306. *
  1307. * @param[in] value Value to be set.
  1308. *
  1309. * @param[in] count Number of uint32_t element to be set to the value.
  1310. *
  1311. * @retval HSA_STATUS_SUCCESS The function has been executed successfully.
  1312. *
  1313. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  1314. * initialized.
  1315. *
  1316. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT @p ptr is NULL or
  1317. * not 4 bytes aligned
  1318. *
  1319. * @retval HSA_STATUS_ERROR_INVALID_ALLOCATION if the given memory
  1320. * region was not allocated with HSA runtime APIs.
  1321. *
  1322. */
  1323. hsa_status_t HSA_API
  1324. hsa_amd_memory_fill(void* ptr, uint32_t value, size_t count);
  1325. /**
  1326. * @brief Maps an interop object into the HSA flat address space and establishes
  1327. * memory residency. The metadata pointer is valid during the lifetime of the
  1328. * map (until hsa_amd_interop_unmap_buffer is called).
  1329. * Multiple calls to hsa_amd_interop_map_buffer with the same interop_handle
  1330. * result in multiple mappings with potentially different addresses and
  1331. * different metadata pointers. Concurrent operations on these addresses are
  1332. * not coherent. Memory must be fenced to system scope to ensure consistency,
  1333. * between mappings and with any views of this buffer in the originating
  1334. * software stack.
  1335. *
  1336. * @param[in] num_agents Number of agents which require access to the memory
  1337. *
  1338. * @param[in] agents List of accessing agents.
  1339. *
  1340. * @param[in] interop_handle Handle of interop buffer (dmabuf handle in Linux)
  1341. *
  1342. * @param [in] flags Reserved, must be 0
  1343. *
  1344. * @param[out] size Size in bytes of the mapped object
  1345. *
  1346. * @param[out] ptr Base address of the mapped object
  1347. *
  1348. * @param[out] metadata_size Size of metadata in bytes, may be NULL
  1349. *
  1350. * @param[out] metadata Pointer to metadata, may be NULL
  1351. *
  1352. * @retval HSA_STATUS_SUCCESS if successfully mapped
  1353. *
  1354. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED if HSA is not initialized
  1355. *
  1356. * @retval HSA_STATUS_ERROR_OUT_OF_RESOURCES if there is a failure in allocating
  1357. * necessary resources
  1358. *
  1359. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT all other errors
  1360. */
  1361. hsa_status_t HSA_API hsa_amd_interop_map_buffer(uint32_t num_agents,
  1362. hsa_agent_t* agents,
  1363. int interop_handle,
  1364. uint32_t flags,
  1365. size_t* size,
  1366. void** ptr,
  1367. size_t* metadata_size,
  1368. const void** metadata);
  1369. /**
  1370. * @brief Removes a previously mapped interop object from HSA's flat address space.
  1371. * Ends lifetime for the mapping's associated metadata pointer.
  1372. */
  1373. hsa_status_t HSA_API hsa_amd_interop_unmap_buffer(void* ptr);
  1374. /**
  1375. * @brief Encodes an opaque vendor specific image format. The length of data
  1376. * depends on the underlying format. This structure must not be copied as its
  1377. * true length can not be determined.
  1378. */
  1379. typedef struct hsa_amd_image_descriptor_s {
  1380. /*
  1381. Version number of the descriptor
  1382. */
  1383. uint32_t version;
  1384. /*
  1385. Vendor and device PCI IDs for the format as VENDOR_ID<<16|DEVICE_ID.
  1386. */
  1387. uint32_t deviceID;
  1388. /*
  1389. Start of vendor specific data.
  1390. */
  1391. uint32_t data[1];
  1392. } hsa_amd_image_descriptor_t;
  1393. /**
  1394. * @brief Creates an image from an opaque vendor specific image format.
  1395. * Does not modify data at image_data. Intended initially for
  1396. * accessing interop images.
  1397. *
  1398. * @param agent[in] Agent on which to create the image
  1399. *
  1400. * @param[in] image_descriptor[in] Vendor specific image format
  1401. *
  1402. * @param[in] image_data Pointer to image backing store
  1403. *
  1404. * @param[in] access_permission Access permissions for the image object
  1405. *
  1406. * @param[out] image Created image object.
  1407. *
  1408. * @retval HSA_STATUS_SUCCESS Image created successfully
  1409. *
  1410. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED if HSA is not initialized
  1411. *
  1412. * @retval HSA_STATUS_ERROR_OUT_OF_RESOURCES if there is a failure in allocating
  1413. * necessary resources
  1414. *
  1415. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT Bad or mismatched descriptor,
  1416. * null image_data, or mismatched access_permission.
  1417. */
  1418. hsa_status_t HSA_API hsa_amd_image_create(
  1419. hsa_agent_t agent,
  1420. const hsa_ext_image_descriptor_t *image_descriptor,
  1421. const hsa_amd_image_descriptor_t *image_layout,
  1422. const void *image_data,
  1423. hsa_access_permission_t access_permission,
  1424. hsa_ext_image_t *image
  1425. );
  1426. /**
  1427. * @brief Denotes the type of memory in a pointer info query.
  1428. */
  1429. typedef enum {
  1430. /*
  1431. Memory is not known to the HSA driver. Unallocated or unlocked system memory.
  1432. */
  1433. HSA_EXT_POINTER_TYPE_UNKNOWN = 0,
  1434. /*
  1435. Memory was allocated with an HSA memory allocator.
  1436. */
  1437. HSA_EXT_POINTER_TYPE_HSA = 1,
  1438. /*
  1439. System memory which has been locked for use with an HSA agent.
  1440. Memory of this type is normal malloc'd memory and is always accessible to
  1441. the CPU. Pointer info queries may not include CPU agents in the accessible
  1442. agents list as the CPU has implicit access.
  1443. */
  1444. HSA_EXT_POINTER_TYPE_LOCKED = 2,
  1445. /*
  1446. Memory originated in a graphics component and is shared with ROCr.
  1447. */
  1448. HSA_EXT_POINTER_TYPE_GRAPHICS = 3,
  1449. /*
  1450. Memory has been shared with the local process via ROCr IPC APIs.
  1451. */
  1452. HSA_EXT_POINTER_TYPE_IPC = 4
  1453. } hsa_amd_pointer_type_t;
  1454. /**
  1455. * @brief Describes a memory allocation known to ROCr.
  1456. * Within a ROCr major version this structure can only grow.
  1457. */
  1458. typedef struct hsa_amd_pointer_info_s {
  1459. /*
  1460. Size in bytes of this structure. Used for version control within a major ROCr
  1461. revision. Set to sizeof(hsa_amd_pointer_t) prior to calling
  1462. hsa_amd_pointer_info. If the runtime supports an older version of pointer
  1463. info then size will be smaller on return. Members starting after the return
  1464. value of size will not be updated by hsa_amd_pointer_info.
  1465. */
  1466. uint32_t size;
  1467. /*
  1468. The type of allocation referenced.
  1469. */
  1470. hsa_amd_pointer_type_t type;
  1471. /*
  1472. Base address at which non-host agents may access the allocation.
  1473. */
  1474. void* agentBaseAddress;
  1475. /*
  1476. Base address at which the host agent may access the allocation.
  1477. */
  1478. void* hostBaseAddress;
  1479. /*
  1480. Size of the allocation
  1481. */
  1482. size_t sizeInBytes;
  1483. /*
  1484. Application provided value.
  1485. */
  1486. void* userData;
  1487. /*
  1488. Reports an agent which "owns" (ie has preferred access to) the pool in which the allocation was
  1489. made. When multiple agents share equal access to a pool (ex: multiple CPU agents, or multi-die
  1490. GPU boards) any such agent may be returned.
  1491. */
  1492. hsa_agent_t agentOwner;
  1493. } hsa_amd_pointer_info_t;
  1494. /**
  1495. * @brief Retrieves information about the allocation referenced by the given
  1496. * pointer. Optionally returns the number and list of agents which can
  1497. * directly access the allocation.
  1498. *
  1499. * @param[in] ptr Pointer which references the allocation to retrieve info for.
  1500. *
  1501. * @param[in, out] info Pointer to structure to be filled with allocation info.
  1502. * Data member size must be set to the size of the structure prior to calling
  1503. * hsa_amd_pointer_info. On return size will be set to the size of the
  1504. * pointer info structure supported by the runtime, if smaller. Members
  1505. * beyond the returned value of size will not be updated by the API.
  1506. * Must not be NULL.
  1507. *
  1508. * @param[in] alloc Function pointer to an allocator used to allocate the
  1509. * @p accessible array. If NULL @p accessible will not be returned.
  1510. *
  1511. * @param[out] num_agents_accessible Recieves the count of agents in
  1512. * @p accessible. If NULL @p accessible will not be returned.
  1513. *
  1514. * @param[out] accessible Recieves a pointer to the array, allocated by @p alloc,
  1515. * holding the list of agents which may directly access the allocation.
  1516. * May be NULL.
  1517. *
  1518. * @retval HSA_STATUS_SUCCESS Info retrieved successfully
  1519. *
  1520. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED if HSA is not initialized
  1521. *
  1522. * @retval HSA_STATUS_ERROR_OUT_OF_RESOURCES if there is a failure in allocating
  1523. * necessary resources
  1524. *
  1525. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT NULL in @p ptr or @p info.
  1526. */
  1527. hsa_status_t HSA_API hsa_amd_pointer_info(void* ptr,
  1528. hsa_amd_pointer_info_t* info,
  1529. void* (*alloc)(size_t),
  1530. uint32_t* num_agents_accessible,
  1531. hsa_agent_t** accessible);
  1532. /**
  1533. * @brief Associates an arbitrary pointer with an allocation known to ROCr.
  1534. * The pointer can be fetched by hsa_amd_pointer_info in the userData field.
  1535. *
  1536. * @param[in] ptr Pointer to the first byte of an allocation known to ROCr
  1537. * with which to associate @p userdata.
  1538. *
  1539. * @param[in] userdata Abitrary pointer to associate with the allocation.
  1540. *
  1541. * @retval HSA_STATUS_SUCCESS @p userdata successfully stored.
  1542. *
  1543. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED if HSA is not initialized
  1544. *
  1545. * @retval HSA_STATUS_ERROR_OUT_OF_RESOURCES if there is a failure in allocating
  1546. * necessary resources
  1547. *
  1548. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT @p ptr is not known to ROCr.
  1549. */
  1550. hsa_status_t HSA_API hsa_amd_pointer_info_set_userdata(void* ptr,
  1551. void* userdata);
  1552. /**
  1553. * @brief 256-bit process independent identifier for a ROCr shared memory
  1554. * allocation.
  1555. */
  1556. typedef struct hsa_amd_ipc_memory_s {
  1557. uint32_t handle[8];
  1558. } hsa_amd_ipc_memory_t;
  1559. /**
  1560. * @brief Prepares an allocation for interprocess sharing and creates a
  1561. * handle of type hsa_amd_ipc_memory_t uniquely identifying the allocation. A
  1562. * handle is valid while the allocation it references remains accessible in
  1563. * any process. In general applications should confirm that a shared memory
  1564. * region has been attached (via hsa_amd_ipc_memory_attach) in the remote
  1565. * process prior to releasing that memory in the local process.
  1566. * Repeated calls for the same allocation may, but are not required to, return
  1567. * unique handles.
  1568. *
  1569. * @param[in] ptr Pointer to memory allocated via ROCr APIs to prepare for
  1570. * sharing.
  1571. *
  1572. * @param[in] len Length in bytes of the allocation to share.
  1573. *
  1574. * @param[out] handle Process independent identifier referencing the shared
  1575. * allocation.
  1576. *
  1577. * @retval HSA_STATUS_SUCCESS allocation is prepared for interprocess sharing.
  1578. *
  1579. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED if HSA is not initialized
  1580. *
  1581. * @retval HSA_STATUS_ERROR_OUT_OF_RESOURCES if there is a failure in allocating
  1582. * necessary resources
  1583. *
  1584. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT @p ptr does not point to the
  1585. * first byte of an allocation made through ROCr, or len is not the full length
  1586. * of the allocation or handle is NULL.
  1587. */
  1588. hsa_status_t HSA_API hsa_amd_ipc_memory_create(void* ptr, size_t len,
  1589. hsa_amd_ipc_memory_t* handle);
  1590. /**
  1591. * @brief Imports shared memory into the local process and makes it accessible
  1592. * by the given agents. If a shared memory handle is attached multiple times
  1593. * in a process each attach may return a different address. Each returned
  1594. * address is refcounted and requires a matching number of calls to
  1595. * hsa_amd_ipc_memory_detach to release the shared memory mapping.
  1596. *
  1597. * @param[in] handle Pointer to the identifier for the shared memory.
  1598. *
  1599. * @param[in] len Length of the shared memory to import.
  1600. * Reserved. Must be the full length of the shared allocation in this version.
  1601. *
  1602. * @param[in] num_agents Count of agents in @p mapping_agents.
  1603. * May be zero if all agents are to be allowed access.
  1604. *
  1605. * @param[in] mapping_agents List of agents to access the shared memory.
  1606. * Ignored if @p num_agents is zero.
  1607. *
  1608. * @param[out] mapped_ptr Recieves a process local pointer to the shared memory.
  1609. *
  1610. * @retval HSA_STATUS_SUCCESS if memory is successfully imported.
  1611. *
  1612. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED if HSA is not initialized
  1613. *
  1614. * @retval HSA_STATUS_ERROR_OUT_OF_RESOURCES if there is a failure in allocating
  1615. * necessary resources
  1616. *
  1617. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT @p handle is not valid, @p len is
  1618. * incorrect, @p mapped_ptr is NULL, or some agent for which access was
  1619. * requested can not access the shared memory.
  1620. */
  1621. hsa_status_t HSA_API hsa_amd_ipc_memory_attach(
  1622. const hsa_amd_ipc_memory_t* handle, size_t len,
  1623. uint32_t num_agents,
  1624. const hsa_agent_t* mapping_agents,
  1625. void** mapped_ptr);
  1626. /**
  1627. * @brief Decrements the reference count for the shared memory mapping and
  1628. * releases access to shared memory imported with hsa_amd_ipc_memory_attach.
  1629. *
  1630. * @param[in] mapped_ptr Pointer to the first byte of a shared allocation
  1631. * imported with hsa_amd_ipc_memory_attach.
  1632. *
  1633. * @retval HSA_STATUS_SUCCESS if @p mapped_ptr was imported with
  1634. * hsa_amd_ipc_memory_attach.
  1635. *
  1636. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED if HSA is not initialized
  1637. *
  1638. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT @p mapped_ptr was not imported
  1639. * with hsa_amd_ipc_memory_attach.
  1640. */
  1641. hsa_status_t HSA_API hsa_amd_ipc_memory_detach(void* mapped_ptr);
  1642. /**
  1643. * @brief 256-bit process independent identifier for a ROCr IPC signal.
  1644. */
  1645. typedef hsa_amd_ipc_memory_t hsa_amd_ipc_signal_t;
  1646. /**
  1647. * @brief Obtains an interprocess sharing handle for a signal. The handle is
  1648. * valid while the signal it references remains valid in any process. In
  1649. * general applications should confirm that the signal has been attached (via
  1650. * hsa_amd_ipc_signal_attach) in the remote process prior to destroying that
  1651. * signal in the local process.
  1652. * Repeated calls for the same signal may, but are not required to, return
  1653. * unique handles.
  1654. *
  1655. * @param[in] signal Signal created with attribute HSA_AMD_SIGNAL_IPC.
  1656. *
  1657. * @param[out] handle Process independent identifier referencing the shared
  1658. * signal.
  1659. *
  1660. * @retval HSA_STATUS_SUCCESS @p handle is ready to use for interprocess sharing.
  1661. *
  1662. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED if HSA is not initialized
  1663. *
  1664. * @retval HSA_STATUS_ERROR_OUT_OF_RESOURCES if there is a failure in allocating
  1665. * necessary resources
  1666. *
  1667. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT @p signal is not a valid signal
  1668. * created with attribute HSA_AMD_SIGNAL_IPC or handle is NULL.
  1669. */
  1670. hsa_status_t HSA_API hsa_amd_ipc_signal_create(hsa_signal_t signal, hsa_amd_ipc_signal_t* handle);
  1671. /**
  1672. * @brief Imports an IPC capable signal into the local process. If an IPC
  1673. * signal handle is attached multiple times in a process each attach may return
  1674. * a different signal handle. Each returned signal handle is refcounted and
  1675. * requires a matching number of calls to hsa_signal_destroy to release the
  1676. * shared signal.
  1677. *
  1678. * @param[in] handle Pointer to the identifier for the shared signal.
  1679. *
  1680. * @param[out] signal Recieves a process local signal handle to the shared signal.
  1681. *
  1682. * @retval HSA_STATUS_SUCCESS if the signal is successfully imported.
  1683. *
  1684. * @retval HSA_STATUS_ERROR_NOT_INITIALIZED if HSA is not initialized
  1685. *
  1686. * @retval HSA_STATUS_ERROR_OUT_OF_RESOURCES if there is a failure in allocating
  1687. * necessary resources
  1688. *
  1689. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT @p handle is not valid.
  1690. */
  1691. hsa_status_t HSA_API hsa_amd_ipc_signal_attach(const hsa_amd_ipc_signal_t* handle,
  1692. hsa_signal_t* signal);
  1693. /**
  1694. * @brief GPU system event type.
  1695. */
  1696. typedef enum hsa_amd_event_type_s {
  1697. /*
  1698. AMD GPU memory fault.
  1699. */
  1700. HSA_AMD_GPU_MEMORY_FAULT_EVENT = 0,
  1701. } hsa_amd_event_type_t;
  1702. /**
  1703. * @brief Flags denoting the cause of a memory fault.
  1704. */
  1705. typedef enum {
  1706. // Page not present or supervisor privilege.
  1707. HSA_AMD_MEMORY_FAULT_PAGE_NOT_PRESENT = 1 << 0,
  1708. // Write access to a read-only page.
  1709. HSA_AMD_MEMORY_FAULT_READ_ONLY = 1 << 1,
  1710. // Execute access to a page marked NX.
  1711. HSA_AMD_MEMORY_FAULT_NX = 1 << 2,
  1712. // GPU attempted access to a host only page.
  1713. HSA_AMD_MEMORY_FAULT_HOST_ONLY = 1 << 3,
  1714. // DRAM ECC failure.
  1715. HSA_AMD_MEMORY_FAULT_DRAM_ECC = 1 << 4,
  1716. // Can't determine the exact fault address.
  1717. HSA_AMD_MEMORY_FAULT_IMPRECISE = 1 << 5,
  1718. // SRAM ECC failure (ie registers, no fault address).
  1719. HSA_AMD_MEMORY_FAULT_SRAM_ECC = 1 << 6,
  1720. // GPU reset following unspecified hang.
  1721. HSA_AMD_MEMORY_FAULT_HANG = 1 << 31
  1722. } hsa_amd_memory_fault_reason_t;
  1723. /**
  1724. * @brief AMD GPU memory fault event data.
  1725. */
  1726. typedef struct hsa_amd_gpu_memory_fault_info_s {
  1727. /*
  1728. The agent where the memory fault occurred.
  1729. */
  1730. hsa_agent_t agent;
  1731. /*
  1732. Virtual address accessed.
  1733. */
  1734. uint64_t virtual_address;
  1735. /*
  1736. Bit field encoding the memory access failure reasons. There could be multiple bits set
  1737. for one fault. Bits are defined in hsa_amd_memory_fault_reason_t.
  1738. */
  1739. uint32_t fault_reason_mask;
  1740. } hsa_amd_gpu_memory_fault_info_t;
  1741. /**
  1742. * @brief AMD GPU event data passed to event handler.
  1743. */
  1744. typedef struct hsa_amd_event_s {
  1745. /*
  1746. The event type.
  1747. */
  1748. hsa_amd_event_type_t event_type;
  1749. union {
  1750. /*
  1751. The memory fault info, only valid when @p event_type is HSA_AMD_GPU_MEMORY_FAULT_EVENT.
  1752. */
  1753. hsa_amd_gpu_memory_fault_info_t memory_fault;
  1754. };
  1755. } hsa_amd_event_t;
  1756. typedef hsa_status_t (*hsa_amd_system_event_callback_t)(const hsa_amd_event_t* event, void* data);
  1757. /**
  1758. * @brief Register AMD GPU event handler.
  1759. *
  1760. * @param[in] callback Callback to be invoked when an event is triggered.
  1761. * The HSA runtime passes two arguments to the callback: @p event
  1762. * is defined per event by the HSA runtime, and @p data is the user data.
  1763. *
  1764. * @param[in] data User data that is passed to @p callback. May be NULL.
  1765. *
  1766. * @retval HSA_STATUS_SUCCESS The handler has been registered successfully.
  1767. *
  1768. * @retval HSA_STATUS_ERROR An event handler has already been registered.
  1769. *
  1770. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT @p event is invalid.
  1771. */
  1772. hsa_status_t HSA_API hsa_amd_register_system_event_handler(hsa_amd_system_event_callback_t callback,
  1773. void* data);
  1774. /**
  1775. * @brief Per-queue dispatch and wavefront scheduling priority.
  1776. */
  1777. typedef enum hsa_amd_queue_priority_s {
  1778. /*
  1779. Below normal/high priority compute and all graphics
  1780. */
  1781. HSA_AMD_QUEUE_PRIORITY_LOW = 0,
  1782. /*
  1783. Above low priority compute, below high priority compute and all graphics
  1784. */
  1785. HSA_AMD_QUEUE_PRIORITY_NORMAL = 1,
  1786. /*
  1787. Above low/normal priority compute and all graphics
  1788. */
  1789. HSA_AMD_QUEUE_PRIORITY_HIGH = 2,
  1790. } hsa_amd_queue_priority_t;
  1791. /**
  1792. * @brief Modifies the dispatch and wavefront scheduling prioirty for a
  1793. * given compute queue. The default is HSA_AMD_QUEUE_PRIORITY_NORMAL.
  1794. *
  1795. * @param[in] queue Compute queue to apply new priority to.
  1796. *
  1797. * @param[in] priority Priority to associate with queue.
  1798. *
  1799. * @retval HSA_STATUS_SUCCESS if priority was changed successfully.
  1800. *
  1801. * @retval HSA_STATUS_ERROR_INVALID_QUEUE if queue is not a valid
  1802. * compute queue handle.
  1803. *
  1804. * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT if priority is not a valid
  1805. * value from hsa_amd_queue_priority_t.
  1806. */
  1807. hsa_status_t HSA_API hsa_amd_queue_set_priority(hsa_queue_t* queue,
  1808. hsa_amd_queue_priority_t priority);
  1809. /**
  1810. * @brief Deallocation notifier function type.
  1811. */
  1812. typedef void (*hsa_amd_deallocation_callback_t)(void* ptr, void* user_data);
  1813. /**
  1814. * @brief Registers a deallocation notifier monitoring for release of agent
  1815. * accessible address @p ptr. If successful, @p callback will be invoked when
  1816. * @p ptr is removed from accessibility from all agents.
  1817. *
  1818. * Notification callbacks are automatically deregistered when they are invoked.
  1819. *
  1820. * Note: The current version supports notifications of address release
  1821. * originating from ::hsa_amd_memory_pool_free. Support for other address
  1822. * release APIs will follow.
  1823. *
  1824. * @param[in] ptr Agent accessible address to monitor for deallocation. Passed
  1825. * to @p callback.
  1826. *
  1827. * @param[in] callback Notifier to be invoked when @p ptr is released from
  1828. * agent accessibility.
  1829. *
  1830. * @param[in] user_data User provided value passed to @p callback. May be NULL.
  1831. *
  1832. * @retval ::HSA_STATUS_SUCCESS The notifier registered successfully
  1833. *
  1834. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  1835. * initialized.
  1836. *
  1837. * @retval ::HSA_STATUS_ERROR_INVALID_ALLOCATION @p ptr does not refer to a valid agent accessible
  1838. * address.
  1839. *
  1840. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL or @p ptr is NULL.
  1841. *
  1842. * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES if there is a failure in allocating
  1843. * necessary resources
  1844. */
  1845. hsa_status_t HSA_API hsa_amd_register_deallocation_callback(void* ptr,
  1846. hsa_amd_deallocation_callback_t callback,
  1847. void* user_data);
  1848. /**
  1849. * @brief Removes a deallocation notifier previously registered with
  1850. * ::hsa_amd_register_deallocation_callback. Arguments must be identical to
  1851. * those given in ::hsa_amd_register_deallocation_callback.
  1852. *
  1853. * @param[in] ptr Agent accessible address which was monitored for deallocation.
  1854. *
  1855. * @param[in] callback Notifier to be removed.
  1856. *
  1857. * @retval ::HSA_STATUS_SUCCESS The notifier has been removed successfully.
  1858. *
  1859. * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been
  1860. * initialized.
  1861. *
  1862. * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT The given notifier was not registered.
  1863. */
  1864. hsa_status_t HSA_API hsa_amd_deregister_deallocation_callback(void* ptr,
  1865. hsa_amd_deallocation_callback_t callback);
  1866. #ifdef __cplusplus
  1867. } // end extern "C" block
  1868. #endif
  1869. #endif // header guard