diff --git a/runtime/hsa-ext-finalize/CMakeLists.txt b/runtime/hsa-ext-finalize/CMakeLists.txt index 736c7d0fa1..6ac49927ff 100755 --- a/runtime/hsa-ext-finalize/CMakeLists.txt +++ b/runtime/hsa-ext-finalize/CMakeLists.txt @@ -57,6 +57,7 @@ add_definitions ( -D__AMD64__ ) add_definitions ( -D__x86_64__ ) add_definitions ( -DAMD_INTERNAL_BUILD ) add_definitions ( -DLITTLEENDIAN_CPU=1 ) +add_definitions ( -D HSA_DEPRECATED= ) ## Set ext runtime module name and project name. set ( FINALIZE_NAME "hsa-ext-finalize" ) diff --git a/runtime/hsa-ext-image/CMakeLists.txt b/runtime/hsa-ext-image/CMakeLists.txt index 335c46b9dd..2592a31dad 100755 --- a/runtime/hsa-ext-image/CMakeLists.txt +++ b/runtime/hsa-ext-image/CMakeLists.txt @@ -56,6 +56,7 @@ add_definitions ( -D__AMD64__ ) add_definitions ( -D__x86_64__ ) add_definitions ( -DAMD_INTERNAL_BUILD ) add_definitions ( -DLITTLEENDIAN_CPU=1 ) +add_definitions ( -D HSA_DEPRECATED= ) ## Set ext runtime module name and project name. set ( IMAGE_NAME "hsa-ext-image" ) diff --git a/runtime/hsa-runtime-tools/CMakeLists.txt b/runtime/hsa-runtime-tools/CMakeLists.txt index 198ddad5c7..d3b9e14567 100755 --- a/runtime/hsa-runtime-tools/CMakeLists.txt +++ b/runtime/hsa-runtime-tools/CMakeLists.txt @@ -38,6 +38,7 @@ add_definitions ( -D__AMD64__ ) add_definitions ( -D__x86_64__ ) add_definitions ( -DAMD_INTERNAL_BUILD ) add_definitions ( -DLITTLEENDIAN_CPU=1 ) +add_definitions ( -D HSA_DEPRECATED= ) ## Set ext runtime module name and project name. set ( TOOLS_NAME "hsa-runtime-tools" ) diff --git a/runtime/hsa-runtime/CMakeLists.txt b/runtime/hsa-runtime/CMakeLists.txt index bf3253c099..276e298663 100644 --- a/runtime/hsa-runtime/CMakeLists.txt +++ b/runtime/hsa-runtime/CMakeLists.txt @@ -46,6 +46,8 @@ project(hsa-runtime) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") +add_definitions (-D HSA_DEPRECATED=) + include(utils) include(hsa_common) diff --git a/runtime/hsa-runtime/core/CMakeLists.txt b/runtime/hsa-runtime/core/CMakeLists.txt index 0eb9af6862..4d4be58bd7 100644 --- a/runtime/hsa-runtime/core/CMakeLists.txt +++ b/runtime/hsa-runtime/core/CMakeLists.txt @@ -100,11 +100,13 @@ endif () ## ------------------------- Linux Compiler and Linker options ------------------------- -set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fexceptions -fno-rtti -fvisibility=hidden -Wno-error=sign-compare -Wno-sign-compare -Wno-write-strings -Wno-deprecated-declarations -Wno-conversion-null -fno-math-errno -fno-threadsafe-statics -fmerge-all-constants -fms-extensions -Wno-error=comment -Wno-comment -Wno-error=pointer-arith -Wno-pointer-arith -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=unused-function" ) +set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fexceptions -fno-rtti -fvisibility=hidden -Wno-error=sign-compare -Wno-sign-compare -Wno-write-strings -Wno-conversion-null -fno-math-errno -fno-threadsafe-statics -fmerge-all-constants -fms-extensions -Wno-error=comment -Wno-comment -Wno-error=pointer-arith -Wno-pointer-arith -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=unused-function" ) set ( DRVDEF "${CMAKE_CURRENT_SOURCE_DIR}/hsacore.so.def" ) -set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack -Wl,--version-script=${DRVDEF}" ) +set ( LNKSCR "${CMAKE_CURRENT_SOURCE_DIR}/hsacore.so.link" ) + +set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bdynamic -Wl,-z,noexecstack -Wl,${LNKSCR} -Wl,--version-script=${DRVDEF}" ) set ( CMAKE_SKIP_BUILD_RPATH TRUE) @@ -133,6 +135,7 @@ set ( CORE_SRCS ${CORE_SRCS} runtime/interrupt_signal.cpp ) set ( CORE_SRCS ${CORE_SRCS} runtime/isa.cpp ) set ( CORE_SRCS ${CORE_SRCS} runtime/runtime.cpp ) set ( CORE_SRCS ${CORE_SRCS} runtime/signal.cpp ) +set ( CORE_SRCS ${CORE_SRCS} runtime/cache.cpp ) set ( CORE_SRCS ${CORE_SRCS} common/shared.cpp ) set ( CORE_SRCS ${CORE_SRCS} common/hsa_table_interface.cpp ) diff --git a/runtime/hsa-runtime/core/common/hsa_table_interface.cpp b/runtime/hsa-runtime/core/common/hsa_table_interface.cpp index 13154820f6..a0370c672b 100644 --- a/runtime/hsa-runtime/core/common/hsa_table_interface.cpp +++ b/runtime/hsa-runtime/core/common/hsa_table_interface.cpp @@ -67,6 +67,11 @@ hsa_status_t HSA_API return coreApiTable->hsa_system_get_info_fn(attribute, value); } +hsa_status_t HSA_API hsa_extension_get_name(uint16_t extension, const char** name) +{ + return coreApiTable->hsa_extension_get_name_fn(extension, name); +} + hsa_status_t HSA_API hsa_system_extension_supported(uint16_t extension, uint16_t version_major, uint16_t version_minor, bool* result) { @@ -74,6 +79,13 @@ hsa_status_t HSA_API extension, version_major, version_minor, result); } +hsa_status_t HSA_API + hsa_system_major_extension_supported(uint16_t extension, uint16_t version_major, + uint16_t *version_minor, bool* result) { + return coreApiTable->hsa_system_major_extension_supported_fn( + extension, version_major, version_minor, result); +} + hsa_status_t HSA_API hsa_system_get_extension_table(uint16_t extension, uint16_t version_major, uint16_t version_minor, void* table) { @@ -81,6 +93,11 @@ hsa_status_t HSA_API extension, version_major, version_minor, table); } +hsa_status_t HSA_API hsa_system_get_major_extension_table(uint16_t extension, uint16_t version_major, size_t table_length, void *table) +{ + return coreApiTable->hsa_system_get_major_extension_table_fn(extension, version_major, table_length, table); +} + hsa_status_t HSA_API hsa_iterate_agents(hsa_status_t (*callback)(hsa_agent_t agent, void* data), void* data) { @@ -99,6 +116,16 @@ hsa_status_t HSA_API hsa_agent_get_exception_policies(hsa_agent_t agent, return coreApiTable->hsa_agent_get_exception_policies_fn(agent, profile, mask); } +hsa_status_t HSA_API hsa_cache_get_info(hsa_cache_t cache, hsa_cache_info_t attribute, void *value) +{ + return coreApiTable->hsa_cache_get_info_fn(cache, attribute, value); +} + +hsa_status_t HSA_API hsa_agent_iterate_caches(hsa_agent_t agent, hsa_status_t (*callback )(hsa_cache_t cache, void *data), void *value) +{ + return coreApiTable->hsa_agent_iterate_caches_fn(agent, callback, value); +} + hsa_status_t HSA_API hsa_agent_extension_supported(uint16_t extension, hsa_agent_t agent, uint16_t version_major, @@ -107,6 +134,11 @@ hsa_status_t HSA_API extension, agent, version_major, version_minor, result); } +hsa_status_t HSA_API hsa_agent_major_extension_supported(uint16_t extension, hsa_agent_t agent, uint16_t version_major, uint16_t *version_minor, bool *result) +{ + return coreApiTable->hsa_agent_major_extension_supported_fn(extension, agent, version_major, version_minor, result); +} + hsa_status_t HSA_API hsa_queue_create(hsa_agent_t agent, uint32_t size, hsa_queue_type_t type, void (*callback)(hsa_status_t status, hsa_queue_t* source, @@ -134,16 +166,16 @@ hsa_status_t HSA_API hsa_queue_inactivate(hsa_queue_t* queue) { return coreApiTable->hsa_queue_inactivate_fn(queue); } -uint64_t HSA_API hsa_queue_load_read_index_acquire(const hsa_queue_t* queue) { - return coreApiTable->hsa_queue_load_read_index_acquire_fn(queue); +uint64_t HSA_API hsa_queue_load_read_index_scacquire(const hsa_queue_t* queue) { + return coreApiTable->hsa_queue_load_read_index_scacquire_fn(queue); } uint64_t HSA_API hsa_queue_load_read_index_relaxed(const hsa_queue_t* queue) { return coreApiTable->hsa_queue_load_read_index_relaxed_fn(queue); } -uint64_t HSA_API hsa_queue_load_write_index_acquire(const hsa_queue_t* queue) { - return coreApiTable->hsa_queue_load_write_index_acquire_fn(queue); +uint64_t HSA_API hsa_queue_load_write_index_scacquire(const hsa_queue_t* queue) { + return coreApiTable->hsa_queue_load_write_index_scacquire_fn(queue); } uint64_t HSA_API hsa_queue_load_write_index_relaxed(const hsa_queue_t* queue) { @@ -155,22 +187,22 @@ void HSA_API hsa_queue_store_write_index_relaxed(const hsa_queue_t* queue, return coreApiTable->hsa_queue_store_write_index_relaxed_fn(queue, value); } -void HSA_API hsa_queue_store_write_index_release(const hsa_queue_t* queue, +void HSA_API hsa_queue_store_write_index_screlease(const hsa_queue_t* queue, uint64_t value) { - return coreApiTable->hsa_queue_store_write_index_release_fn(queue, value); + return coreApiTable->hsa_queue_store_write_index_screlease_fn(queue, value); } -uint64_t HSA_API hsa_queue_cas_write_index_acq_rel(const hsa_queue_t* queue, +uint64_t HSA_API hsa_queue_cas_write_index_scacq_screl(const hsa_queue_t* queue, uint64_t expected, uint64_t value) { - return coreApiTable->hsa_queue_cas_write_index_acq_rel_fn(queue, expected, + return coreApiTable->hsa_queue_cas_write_index_scacq_screl_fn(queue, expected, value); } -uint64_t HSA_API hsa_queue_cas_write_index_acquire(const hsa_queue_t* queue, +uint64_t HSA_API hsa_queue_cas_write_index_scacquire(const hsa_queue_t* queue, uint64_t expected, uint64_t value) { - return coreApiTable->hsa_queue_cas_write_index_acquire_fn(queue, expected, + return coreApiTable->hsa_queue_cas_write_index_scacquire_fn(queue, expected, value); } @@ -181,21 +213,21 @@ uint64_t HSA_API hsa_queue_cas_write_index_relaxed(const hsa_queue_t* queue, value); } -uint64_t HSA_API hsa_queue_cas_write_index_release(const hsa_queue_t* queue, +uint64_t HSA_API hsa_queue_cas_write_index_screlease(const hsa_queue_t* queue, uint64_t expected, uint64_t value) { - return coreApiTable->hsa_queue_cas_write_index_release_fn(queue, expected, + return coreApiTable->hsa_queue_cas_write_index_screlease_fn(queue, expected, value); } -uint64_t HSA_API hsa_queue_add_write_index_acq_rel(const hsa_queue_t* queue, +uint64_t HSA_API hsa_queue_add_write_index_scacq_screl(const hsa_queue_t* queue, uint64_t value) { - return coreApiTable->hsa_queue_add_write_index_acq_rel_fn(queue, value); + return coreApiTable->hsa_queue_add_write_index_scacq_screl_fn(queue, value); } -uint64_t HSA_API hsa_queue_add_write_index_acquire(const hsa_queue_t* queue, +uint64_t HSA_API hsa_queue_add_write_index_scacquire(const hsa_queue_t* queue, uint64_t value) { - return coreApiTable->hsa_queue_add_write_index_acquire_fn(queue, value); + return coreApiTable->hsa_queue_add_write_index_scacquire_fn(queue, value); } uint64_t HSA_API hsa_queue_add_write_index_relaxed(const hsa_queue_t* queue, @@ -203,9 +235,9 @@ uint64_t HSA_API hsa_queue_add_write_index_relaxed(const hsa_queue_t* queue, return coreApiTable->hsa_queue_add_write_index_relaxed_fn(queue, value); } -uint64_t HSA_API hsa_queue_add_write_index_release(const hsa_queue_t* queue, +uint64_t HSA_API hsa_queue_add_write_index_screlease(const hsa_queue_t* queue, uint64_t value) { - return coreApiTable->hsa_queue_add_write_index_release_fn(queue, value); + return coreApiTable->hsa_queue_add_write_index_screlease_fn(queue, value); } void HSA_API hsa_queue_store_read_index_relaxed(const hsa_queue_t* queue, @@ -213,9 +245,9 @@ void HSA_API hsa_queue_store_read_index_relaxed(const hsa_queue_t* queue, return coreApiTable->hsa_queue_store_read_index_relaxed_fn(queue, value); } -void HSA_API hsa_queue_store_read_index_release(const hsa_queue_t* queue, +void HSA_API hsa_queue_store_read_index_screlease(const hsa_queue_t* queue, uint64_t value) { - return coreApiTable->hsa_queue_store_read_index_release_fn(queue, value); + return coreApiTable->hsa_queue_store_read_index_screlease_fn(queue, value); } hsa_status_t HSA_API hsa_agent_iterate_regions( @@ -271,8 +303,8 @@ hsa_signal_value_t HSA_API hsa_signal_load_relaxed(hsa_signal_t signal) { return coreApiTable->hsa_signal_load_relaxed_fn(signal); } -hsa_signal_value_t HSA_API hsa_signal_load_acquire(hsa_signal_t signal) { - return coreApiTable->hsa_signal_load_acquire_fn(signal); +hsa_signal_value_t HSA_API hsa_signal_load_scacquire(hsa_signal_t signal) { + return coreApiTable->hsa_signal_load_scacquire_fn(signal); } void HSA_API @@ -281,8 +313,18 @@ void HSA_API } void HSA_API - hsa_signal_store_release(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_store_release_fn(signal, value); + hsa_signal_store_screlease(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_store_screlease_fn(signal, value); +} + +void HSA_API hsa_signal_silent_store_relaxed(hsa_signal_t signal, hsa_signal_value_t value) +{ + return coreApiTable->hsa_signal_silent_store_relaxed_fn(signal, value); +} + +void HSA_API hsa_signal_silent_store_screlease(hsa_signal_t signal, hsa_signal_value_t value) +{ + return coreApiTable->hsa_signal_silent_store_screlease_fn(signal, value); } hsa_signal_value_t HSA_API @@ -296,33 +338,53 @@ hsa_signal_value_t HSA_API } hsa_signal_value_t HSA_API - hsa_signal_wait_acquire(hsa_signal_t signal, + hsa_signal_wait_scacquire(hsa_signal_t signal, hsa_signal_condition_t condition, hsa_signal_value_t compare_value, uint64_t timeout_hint, hsa_wait_state_t wait_expectancy_hint) { - return coreApiTable->hsa_signal_wait_acquire_fn( + return coreApiTable->hsa_signal_wait_scacquire_fn( signal, condition, compare_value, timeout_hint, wait_expectancy_hint); } +hsa_status_t HSA_API hsa_signal_group_create(uint32_t num_signals, const hsa_signal_t *signals, uint32_t num_consumers, const hsa_agent_t *consumers, hsa_signal_group_t *signal_group) +{ + return coreApiTable->hsa_signal_group_create_fn(num_signals, signals, num_consumers, consumers, signal_group); +} + +hsa_status_t HSA_API hsa_signal_group_destroy(hsa_signal_group_t signal_group) +{ + return coreApiTable->hsa_signal_group_destroy_fn(signal_group); +} + +hsa_status_t HSA_API hsa_signal_group_wait_any_relaxed(hsa_signal_group_t signal_group, const hsa_signal_condition_t *conditions, const hsa_signal_value_t *compare_values, hsa_wait_state_t wait_state_hint, hsa_signal_t *signal, hsa_signal_value_t *value) +{ + return coreApiTable->hsa_signal_group_wait_any_relaxed_fn(signal_group, conditions, compare_values, wait_state_hint, signal, value); +} + +hsa_status_t HSA_API hsa_signal_group_wait_any_scacquire(hsa_signal_group_t signal_group, const hsa_signal_condition_t *conditions, const hsa_signal_value_t *compare_values, hsa_wait_state_t wait_state_hint, hsa_signal_t *signal, hsa_signal_value_t *value) +{ + return coreApiTable->hsa_signal_group_wait_any_scacquire_fn(signal_group, conditions, compare_values, wait_state_hint, signal, value); +} + void HSA_API hsa_signal_and_relaxed(hsa_signal_t signal, hsa_signal_value_t value) { return coreApiTable->hsa_signal_and_relaxed_fn(signal, value); } void HSA_API - hsa_signal_and_acquire(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_and_acquire_fn(signal, value); + hsa_signal_and_scacquire(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_and_scacquire_fn(signal, value); } void HSA_API - hsa_signal_and_release(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_and_release_fn(signal, value); + hsa_signal_and_screlease(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_and_screlease_fn(signal, value); } void HSA_API - hsa_signal_and_acq_rel(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_and_acq_rel_fn(signal, value); + hsa_signal_and_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_and_scacq_screl_fn(signal, value); } void HSA_API @@ -331,18 +393,18 @@ void HSA_API } void HSA_API - hsa_signal_or_acquire(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_or_acquire_fn(signal, value); + hsa_signal_or_scacquire(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_or_scacquire_fn(signal, value); } void HSA_API - hsa_signal_or_release(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_or_release_fn(signal, value); + hsa_signal_or_screlease(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_or_screlease_fn(signal, value); } void HSA_API - hsa_signal_or_acq_rel(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_or_acq_rel_fn(signal, value); + hsa_signal_or_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_or_scacq_screl_fn(signal, value); } void HSA_API @@ -351,18 +413,18 @@ void HSA_API } void HSA_API - hsa_signal_xor_acquire(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_xor_acquire_fn(signal, value); + hsa_signal_xor_scacquire(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_xor_scacquire_fn(signal, value); } void HSA_API - hsa_signal_xor_release(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_xor_release_fn(signal, value); + hsa_signal_xor_screlease(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_xor_screlease_fn(signal, value); } void HSA_API - hsa_signal_xor_acq_rel(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_xor_acq_rel_fn(signal, value); + hsa_signal_xor_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_xor_scacq_screl_fn(signal, value); } void HSA_API @@ -371,18 +433,18 @@ void HSA_API } void HSA_API - hsa_signal_add_acquire(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_add_acquire_fn(signal, value); + hsa_signal_add_scacquire(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_add_scacquire_fn(signal, value); } void HSA_API - hsa_signal_add_release(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_add_release_fn(signal, value); + hsa_signal_add_screlease(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_add_screlease_fn(signal, value); } void HSA_API - hsa_signal_add_acq_rel(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_add_acq_rel_fn(signal, value); + hsa_signal_add_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_add_scacq_screl_fn(signal, value); } void HSA_API @@ -391,18 +453,18 @@ void HSA_API } void HSA_API - hsa_signal_subtract_acquire(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_subtract_acquire_fn(signal, value); + hsa_signal_subtract_scacquire(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_subtract_scacquire_fn(signal, value); } void HSA_API - hsa_signal_subtract_release(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_subtract_release_fn(signal, value); + hsa_signal_subtract_screlease(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_subtract_screlease_fn(signal, value); } void HSA_API - hsa_signal_subtract_acq_rel(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_subtract_acq_rel_fn(signal, value); + hsa_signal_subtract_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_subtract_scacq_screl_fn(signal, value); } hsa_signal_value_t HSA_API @@ -411,18 +473,18 @@ hsa_signal_value_t HSA_API } hsa_signal_value_t HSA_API - hsa_signal_exchange_acquire(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_exchange_acquire_fn(signal, value); + hsa_signal_exchange_scacquire(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_exchange_scacquire_fn(signal, value); } hsa_signal_value_t HSA_API - hsa_signal_exchange_release(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_exchange_release_fn(signal, value); + hsa_signal_exchange_screlease(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_exchange_screlease_fn(signal, value); } hsa_signal_value_t HSA_API - hsa_signal_exchange_acq_rel(hsa_signal_t signal, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_exchange_acq_rel_fn(signal, value); + hsa_signal_exchange_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value) { + return coreApiTable->hsa_signal_exchange_scacq_screl_fn(signal, value); } hsa_signal_value_t HSA_API hsa_signal_cas_relaxed(hsa_signal_t signal, @@ -431,184 +493,359 @@ hsa_signal_value_t HSA_API hsa_signal_cas_relaxed(hsa_signal_t signal, return coreApiTable->hsa_signal_cas_relaxed_fn(signal, expected, value); } -hsa_signal_value_t HSA_API hsa_signal_cas_acquire(hsa_signal_t signal, +hsa_signal_value_t HSA_API hsa_signal_cas_scacquire(hsa_signal_t signal, hsa_signal_value_t expected, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_cas_acquire_fn(signal, expected, value); + return coreApiTable->hsa_signal_cas_scacquire_fn(signal, expected, value); } -hsa_signal_value_t HSA_API hsa_signal_cas_release(hsa_signal_t signal, +hsa_signal_value_t HSA_API hsa_signal_cas_screlease(hsa_signal_t signal, hsa_signal_value_t expected, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_cas_release_fn(signal, expected, value); + return coreApiTable->hsa_signal_cas_screlease_fn(signal, expected, value); } -hsa_signal_value_t HSA_API hsa_signal_cas_acq_rel(hsa_signal_t signal, +hsa_signal_value_t HSA_API hsa_signal_cas_scacq_screl(hsa_signal_t signal, hsa_signal_value_t expected, hsa_signal_value_t value) { - return coreApiTable->hsa_signal_cas_acq_rel_fn(signal, expected, value); + return coreApiTable->hsa_signal_cas_scacq_screl_fn(signal, expected, value); } -hsa_status_t hsa_isa_from_name(const char* name, hsa_isa_t* isa) { +//===--- Instruction Set Architecture -------------------------------------===// + +hsa_status_t HSA_API hsa_isa_from_name( + const char *name, + hsa_isa_t *isa) { return coreApiTable->hsa_isa_from_name_fn(name, isa); } -hsa_status_t HSA_API hsa_isa_get_info(hsa_isa_t isa, hsa_isa_info_t attribute, - uint32_t index, void* value) { +hsa_status_t HSA_API hsa_agent_iterate_isas( + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_isa_t isa, + void *data), + void *data) { + return coreApiTable->hsa_agent_iterate_isas_fn(agent, callback, data); +} + +/* deprecated */ hsa_status_t HSA_API hsa_isa_get_info( + hsa_isa_t isa, + hsa_isa_info_t attribute, + uint32_t index, + void *value) { return coreApiTable->hsa_isa_get_info_fn(isa, attribute, index, value); } -hsa_status_t hsa_isa_compatible(hsa_isa_t code_object_isa, hsa_isa_t agent_isa, - bool* result) { - return coreApiTable->hsa_isa_compatible_fn(code_object_isa, agent_isa, result); +hsa_status_t HSA_API hsa_isa_get_info_alt( + hsa_isa_t isa, + hsa_isa_info_t attribute, + void *value) { + return coreApiTable->hsa_isa_get_info_alt_fn(isa, attribute, value); } -hsa_status_t HSA_API hsa_code_object_serialize( +hsa_status_t HSA_API hsa_isa_get_exception_policies( + hsa_isa_t isa, + hsa_profile_t profile, + uint16_t *mask) { + return coreApiTable->hsa_isa_get_exception_policies_fn(isa, profile, mask); +} + +hsa_status_t HSA_API hsa_isa_get_round_method( + hsa_isa_t isa, + hsa_fp_type_t fp_type, + hsa_flush_mode_t flush_mode, + hsa_round_method_t *round_method) { + return coreApiTable->hsa_isa_get_round_method_fn( + isa, fp_type, flush_mode, round_method); +} + +hsa_status_t HSA_API hsa_wavefront_get_info( + hsa_wavefront_t wavefront, + hsa_wavefront_info_t attribute, + void *value) { + return coreApiTable->hsa_wavefront_get_info_fn(wavefront, attribute, value); +} + +hsa_status_t HSA_API hsa_isa_iterate_wavefronts( + hsa_isa_t isa, + hsa_status_t (*callback)(hsa_wavefront_t wavefront, + void *data), + void *data) { + return coreApiTable->hsa_isa_iterate_wavefronts_fn(isa, callback, data); +} + +/* deprecated */ hsa_status_t HSA_API hsa_isa_compatible( + hsa_isa_t code_object_isa, + hsa_isa_t agent_isa, + bool *result) { + return coreApiTable->hsa_isa_compatible_fn( + code_object_isa, agent_isa, result); +} + +//===--- Code Objects (deprecated) ----------------------------------------===// + +/* deprecated */ hsa_status_t HSA_API hsa_code_object_serialize( hsa_code_object_t code_object, - hsa_status_t (*alloc_callback)(size_t size, hsa_callback_data_t data, - void** address), - hsa_callback_data_t callback_data, const char* options, - void** serialized_code_object, size_t* serialized_code_object_size) { + hsa_status_t (*alloc_callback)(size_t size, + hsa_callback_data_t data, + void **address), + hsa_callback_data_t callback_data, + const char *options, + void **serialized_code_object, + size_t *serialized_code_object_size) { return coreApiTable->hsa_code_object_serialize_fn( code_object, alloc_callback, callback_data, options, serialized_code_object, serialized_code_object_size); } -hsa_status_t HSA_API - hsa_code_object_deserialize(void* serialized_code_object, - size_t serialized_code_object_size, - const char* options, - hsa_code_object_t* code_object) { +/* deprecated */ hsa_status_t HSA_API hsa_code_object_deserialize( + void *serialized_code_object, + size_t serialized_code_object_size, + const char *options, + hsa_code_object_t *code_object) { return coreApiTable->hsa_code_object_deserialize_fn( serialized_code_object, serialized_code_object_size, options, code_object); } -hsa_status_t HSA_API hsa_code_object_destroy(hsa_code_object_t code_object) { +/* deprecated */ hsa_status_t HSA_API hsa_code_object_destroy( + hsa_code_object_t code_object) { return coreApiTable->hsa_code_object_destroy_fn(code_object); } -hsa_status_t HSA_API hsa_code_object_get_info(hsa_code_object_t code_object, - hsa_code_object_info_t attribute, - void* value) { - return coreApiTable->hsa_code_object_get_info_fn(code_object, attribute, - value); +/* deprecated */ hsa_status_t HSA_API hsa_code_object_get_info( + hsa_code_object_t code_object, + hsa_code_object_info_t attribute, + void *value) { + return coreApiTable->hsa_code_object_get_info_fn( + code_object, attribute, value); } -hsa_status_t HSA_API hsa_code_object_get_symbol(hsa_code_object_t code_object, - const char* symbol_name, - hsa_code_symbol_t* symbol) { - return coreApiTable->hsa_code_object_get_symbol_fn(code_object, symbol_name, - symbol); +/* deprecated */ hsa_status_t HSA_API hsa_code_object_get_symbol( + hsa_code_object_t code_object, + const char *symbol_name, + hsa_code_symbol_t *symbol) { + return coreApiTable->hsa_code_object_get_symbol_fn( + code_object, symbol_name, symbol); } -hsa_status_t HSA_API hsa_code_symbol_get_info(hsa_code_symbol_t code_symbol, - hsa_code_symbol_info_t attribute, - void* value) { - return coreApiTable->hsa_code_symbol_get_info_fn(code_symbol, attribute, - value); +/* deprecated */ hsa_status_t HSA_API hsa_code_object_get_symbol_from_name( + hsa_code_object_t code_object, + const char *module_name, + const char *symbol_name, + hsa_code_symbol_t *symbol) { + return coreApiTable->hsa_code_object_get_symbol_from_name_fn( + code_object, module_name, symbol_name, symbol); } -hsa_status_t HSA_API hsa_code_object_iterate_symbols( +/* deprecated */ hsa_status_t HSA_API hsa_code_symbol_get_info( + hsa_code_symbol_t code_symbol, + hsa_code_symbol_info_t attribute, + void *value) { + return coreApiTable->hsa_code_symbol_get_info_fn( + code_symbol, attribute, value); +} + +/* deprecated */ hsa_status_t HSA_API hsa_code_object_iterate_symbols( hsa_code_object_t code_object, hsa_status_t (*callback)(hsa_code_object_t code_object, - hsa_code_symbol_t symbol, void* data), - void* data) { - return coreApiTable->hsa_code_object_iterate_symbols_fn(code_object, callback, - data); + hsa_code_symbol_t symbol, + void *data), + void *data) { + return coreApiTable->hsa_code_object_iterate_symbols_fn( + code_object, callback, data); } -hsa_status_t HSA_API - hsa_executable_create(hsa_profile_t profile, - hsa_executable_state_t executable_state, - const char* options, hsa_executable_t* executable) { - return coreApiTable->hsa_executable_create_fn(profile, executable_state, - options, executable); +//===--- Executable -------------------------------------------------------===// + +hsa_status_t HSA_API hsa_code_object_reader_create_from_file( + hsa_file_t file, + hsa_code_object_reader_t *code_object_reader) { + return coreApiTable->hsa_code_object_reader_create_from_file_fn( + file, code_object_reader); } -hsa_status_t HSA_API hsa_executable_destroy(hsa_executable_t executable) { +hsa_status_t HSA_API hsa_code_object_reader_create_from_memory( + const void *code_object, + size_t size, + hsa_code_object_reader_t *code_object_reader) { + return coreApiTable->hsa_code_object_reader_create_from_memory_fn( + code_object, size, code_object_reader); +} + +hsa_status_t HSA_API hsa_code_object_reader_destroy( + hsa_code_object_reader_t code_object_reader) { + return coreApiTable->hsa_code_object_reader_destroy_fn(code_object_reader); +} + +/* deprecated */ hsa_status_t HSA_API hsa_executable_create( + hsa_profile_t profile, + hsa_executable_state_t executable_state, + const char *options, + hsa_executable_t *executable) { + return coreApiTable->hsa_executable_create_fn( + profile, executable_state, options, executable); +} + +hsa_status_t HSA_API hsa_executable_create_alt( + hsa_profile_t profile, + hsa_default_float_rounding_mode_t default_float_rounding_mode, + const char *options, + hsa_executable_t *executable) { + return coreApiTable->hsa_executable_create_alt_fn( + profile, default_float_rounding_mode, options, executable); +} + +hsa_status_t HSA_API hsa_executable_destroy( + hsa_executable_t executable) { return coreApiTable->hsa_executable_destroy_fn(executable); } -hsa_status_t HSA_API - hsa_executable_load_code_object(hsa_executable_t executable, - hsa_agent_t agent, - hsa_code_object_t code_object, - const char* options) { - return coreApiTable->hsa_executable_load_code_object_fn(executable, agent, - code_object, options); +/* deprecated */ hsa_status_t HSA_API hsa_executable_load_code_object( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_code_object_t code_object, + const char *options) { + return coreApiTable->hsa_executable_load_code_object_fn( + executable, agent, code_object, options); } -hsa_status_t HSA_API - hsa_executable_freeze(hsa_executable_t executable, const char* options) { +hsa_status_t HSA_API hsa_executable_load_program_code_object( + hsa_executable_t executable, + hsa_code_object_reader_t code_object_reader, + const char *options, + hsa_loaded_code_object_t *loaded_code_object) { + return coreApiTable->hsa_executable_load_program_code_object_fn( + executable, code_object_reader, options, loaded_code_object); +} + +hsa_status_t HSA_API hsa_executable_load_agent_code_object( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_code_object_reader_t code_object_reader, + const char *options, + hsa_loaded_code_object_t *loaded_code_object) { + return coreApiTable->hsa_executable_load_agent_code_object_fn( + executable, agent, code_object_reader, options, loaded_code_object); +} + +hsa_status_t HSA_API hsa_executable_freeze( + hsa_executable_t executable, + const char *options) { return coreApiTable->hsa_executable_freeze_fn(executable, options); } -hsa_status_t HSA_API hsa_executable_get_info(hsa_executable_t executable, - hsa_executable_info_t attribute, - void* value) { +hsa_status_t HSA_API hsa_executable_get_info( + hsa_executable_t executable, + hsa_executable_info_t attribute, + void *value) { return coreApiTable->hsa_executable_get_info_fn(executable, attribute, value); } -hsa_status_t HSA_API - hsa_executable_global_variable_define(hsa_executable_t executable, - const char* variable_name, - void* address) { +hsa_status_t HSA_API hsa_executable_global_variable_define( + hsa_executable_t executable, + const char *variable_name, + void *address) { return coreApiTable->hsa_executable_global_variable_define_fn( executable, variable_name, address); } -hsa_status_t HSA_API - hsa_executable_agent_global_variable_define(hsa_executable_t executable, - hsa_agent_t agent, - const char* variable_name, - void* address) { +hsa_status_t HSA_API hsa_executable_agent_global_variable_define( + hsa_executable_t executable, + hsa_agent_t agent, + const char *variable_name, + void *address) { return coreApiTable->hsa_executable_agent_global_variable_define_fn( executable, agent, variable_name, address); } -hsa_status_t HSA_API - hsa_executable_readonly_variable_define(hsa_executable_t executable, - hsa_agent_t agent, - const char* variable_name, - void* address) { +hsa_status_t HSA_API hsa_executable_readonly_variable_define( + hsa_executable_t executable, + hsa_agent_t agent, + const char *variable_name, + void *address) { return coreApiTable->hsa_executable_readonly_variable_define_fn( executable, agent, variable_name, address); } -hsa_status_t HSA_API - hsa_executable_validate(hsa_executable_t executable, uint32_t* result) { +hsa_status_t HSA_API hsa_executable_validate( + hsa_executable_t executable, + uint32_t *result) { return coreApiTable->hsa_executable_validate_fn(executable, result); } -hsa_status_t HSA_API - hsa_executable_get_symbol(hsa_executable_t executable, - const char* module_name, const char* symbol_name, - hsa_agent_t agent, int32_t call_convention, - hsa_executable_symbol_t* symbol) { +hsa_status_t HSA_API hsa_executable_validate_alt( + hsa_executable_t executable, + const char *options, + uint32_t *result) { + return coreApiTable->hsa_executable_validate_alt_fn( + executable, options, result); +} + +/* deprecated */ hsa_status_t HSA_API hsa_executable_get_symbol( + hsa_executable_t executable, + const char *module_name, + const char *symbol_name, + hsa_agent_t agent, + int32_t call_convention, + hsa_executable_symbol_t *symbol) { return coreApiTable->hsa_executable_get_symbol_fn( executable, module_name, symbol_name, agent, call_convention, symbol); } -hsa_status_t HSA_API - hsa_executable_symbol_get_info(hsa_executable_symbol_t executable_symbol, - hsa_executable_symbol_info_t attribute, - void* value) { - return coreApiTable->hsa_executable_symbol_get_info_fn(executable_symbol, - attribute, value); +hsa_status_t HSA_API hsa_executable_get_symbol_by_name( + hsa_executable_t executable, + const char *symbol_name, + const hsa_agent_t *agent, + hsa_executable_symbol_t *symbol) { + return coreApiTable->hsa_executable_get_symbol_by_name_fn( + executable, symbol_name, agent, symbol); } -hsa_status_t HSA_API hsa_executable_iterate_symbols( +hsa_status_t HSA_API hsa_executable_symbol_get_info( + hsa_executable_symbol_t executable_symbol, + hsa_executable_symbol_info_t attribute, + void *value) { + return coreApiTable->hsa_executable_symbol_get_info_fn( + executable_symbol, attribute, value); +} + +/* deprecated */ hsa_status_t HSA_API hsa_executable_iterate_symbols( hsa_executable_t executable, hsa_status_t (*callback)(hsa_executable_t executable, - hsa_executable_symbol_t symbol, void* data), - void* data) { - return coreApiTable->hsa_executable_iterate_symbols_fn(executable, callback, - data); + hsa_executable_symbol_t symbol, + void *data), + void *data) { + return coreApiTable->hsa_executable_iterate_symbols_fn( + executable, callback, data); } -hsa_status_t HSA_API - hsa_status_string(hsa_status_t status, const char** status_string) { +hsa_status_t HSA_API hsa_executable_iterate_agent_symbols( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_agent_t agent, + hsa_executable_symbol_t symbol, + void *data), + void *data) { + return coreApiTable->hsa_executable_iterate_agent_symbols_fn( + executable, agent, callback, data); +} + +hsa_status_t HSA_API hsa_executable_iterate_program_symbols( + hsa_executable_t executable, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_executable_symbol_t symbol, + void *data), + void *data) { + return coreApiTable->hsa_executable_iterate_program_symbols_fn( + executable, callback, data); +} + +//===--- Runtime Notifications --------------------------------------------===// + +hsa_status_t HSA_API hsa_status_string( + hsa_status_t status, + const char **status_string) { return coreApiTable->hsa_status_string_fn(status, status_string); } diff --git a/runtime/hsa-runtime/core/hsacore.so.def b/runtime/hsa-runtime/core/hsacore.so.def index 130dd0875c..8171073673 100644 --- a/runtime/hsa-runtime/core/hsacore.so.def +++ b/runtime/hsa-runtime/core/hsacore.so.def @@ -1,34 +1,49 @@ -ROCR_1 { global: hsa_init; hsa_shut_down; hsa_system_get_info; + hsa_extension_get_name; hsa_system_extension_supported; + hsa_system_major_extension_supported; hsa_system_get_extension_table; + hsa_system_get_major_extension_table; hsa_iterate_agents; hsa_agent_get_info; hsa_agent_get_exception_policies; + hsa_cache_get_info; + hsa_agent_iterate_caches; hsa_agent_extension_supported; + hsa_agent_major_extension_supported; hsa_queue_create; hsa_soft_queue_create; hsa_queue_destroy; hsa_queue_inactivate; + hsa_queue_load_read_index_scacquire; hsa_queue_load_read_index_acquire; hsa_queue_load_read_index_relaxed; + hsa_queue_load_write_index_scacquire; hsa_queue_load_write_index_acquire; hsa_queue_load_write_index_relaxed; hsa_queue_store_write_index_relaxed; + hsa_queue_store_write_index_screlease; hsa_queue_store_write_index_release; + hsa_queue_cas_write_index_scacq_screl; hsa_queue_cas_write_index_acq_rel; + hsa_queue_cas_write_index_scacquire; hsa_queue_cas_write_index_acquire; hsa_queue_cas_write_index_relaxed; + hsa_queue_cas_write_index_screlease; hsa_queue_cas_write_index_release; + hsa_queue_add_write_index_scacq_screl; hsa_queue_add_write_index_acq_rel; + hsa_queue_add_write_index_scacquire; hsa_queue_add_write_index_acquire; hsa_queue_add_write_index_relaxed; + hsa_queue_add_write_index_screlease; hsa_queue_add_write_index_release; hsa_queue_store_read_index_relaxed; + hsa_queue_store_read_index_screlease; hsa_queue_store_read_index_release; hsa_agent_iterate_regions; hsa_region_get_info; @@ -41,61 +56,107 @@ global: hsa_signal_create; hsa_signal_destroy; hsa_signal_load_relaxed; + hsa_signal_load_scacquire; hsa_signal_load_acquire; hsa_signal_store_relaxed; + hsa_signal_store_screlease; hsa_signal_store_release; + hsa_signal_silent_store_relaxed; + hsa_signal_silent_store_screlease; hsa_signal_wait_relaxed; + hsa_signal_wait_scacquire; hsa_signal_wait_acquire; + hsa_signal_group_create; + hsa_signal_group_destroy; + hsa_signal_group_wait_any_scacquire; hsa_signal_and_relaxed; + hsa_signal_and_scacquire; hsa_signal_and_acquire; + hsa_signal_and_screlease; hsa_signal_and_release; + hsa_signal_and_scacq_screl; hsa_signal_and_acq_rel; hsa_signal_or_relaxed; + hsa_signal_or_scacquire; hsa_signal_or_acquire; + hsa_signal_or_screlease; hsa_signal_or_release; + hsa_signal_or_scacq_screl; hsa_signal_or_acq_rel; hsa_signal_xor_relaxed; + hsa_signal_xor_scacquire; hsa_signal_xor_acquire; + hsa_signal_xor_screlease; hsa_signal_xor_release; + hsa_signal_xor_scacq_screl; hsa_signal_xor_acq_rel; hsa_signal_exchange_relaxed; + hsa_signal_exchange_scacquire; hsa_signal_exchange_acquire; + hsa_signal_exchange_screlease; hsa_signal_exchange_release; + hsa_signal_exchange_scacq_screl; hsa_signal_exchange_acq_rel; hsa_signal_add_relaxed; + hsa_signal_add_scacquire; hsa_signal_add_acquire; + hsa_signal_add_screlease; hsa_signal_add_release; + hsa_signal_add_scacq_screl; hsa_signal_add_acq_rel; hsa_signal_subtract_relaxed; + hsa_signal_subtract_scacquire; hsa_signal_subtract_acquire; + hsa_signal_subtract_screlease; hsa_signal_subtract_release; + hsa_signal_subtract_scacq_screl; hsa_signal_subtract_acq_rel; hsa_signal_cas_relaxed; + hsa_signal_cas_scacquire; hsa_signal_cas_acquire; + hsa_signal_cas_screlease; hsa_signal_cas_release; + hsa_signal_cas_scacq_screl; hsa_signal_cas_acq_rel; hsa_isa_from_name; + hsa_agent_iterate_isas; hsa_isa_get_info; + hsa_isa_get_info_alt; + hsa_isa_get_exception_policies; + hsa_isa_get_round_method; + hsa_wavefront_get_info; + hsa_isa_iterate_wavefronts; hsa_isa_compatible; hsa_code_object_serialize; hsa_code_object_deserialize; hsa_code_object_destroy; hsa_code_object_get_info; hsa_code_object_get_symbol; + hsa_code_object_get_symbol_from_name; hsa_code_symbol_get_info; hsa_code_object_iterate_symbols; + hsa_code_object_reader_create_from_file; + hsa_code_object_reader_create_from_memory; + hsa_code_object_reader_destroy; hsa_executable_create; + hsa_executable_create_alt; hsa_executable_destroy; hsa_executable_load_code_object; + hsa_executable_load_program_code_object; + hsa_executable_load_agent_code_object; hsa_executable_freeze; hsa_executable_get_info; hsa_executable_global_variable_define; hsa_executable_agent_global_variable_define; hsa_executable_readonly_variable_define; hsa_executable_validate; + hsa_executable_validate_alt; hsa_executable_get_symbol; + hsa_executable_get_symbol_by_name; hsa_executable_symbol_get_info; hsa_executable_iterate_symbols; + hsa_executable_iterate_agent_symbols; + hsa_executable_iterate_program_symbols; hsa_status_string; hsa_ext_program_create; hsa_ext_program_destroy; diff --git a/runtime/hsa-runtime/core/hsacore.so.link b/runtime/hsa-runtime/core/hsacore.so.link new file mode 100644 index 0000000000..d67d33da92 --- /dev/null +++ b/runtime/hsa-runtime/core/hsacore.so.link @@ -0,0 +1,34 @@ +hsa_queue_load_read_index_acquire = hsa_queue_load_read_index_scacquire; +hsa_queue_load_write_index_acquire = hsa_queue_load_write_index_scacquire; +hsa_queue_store_write_index_release = hsa_queue_store_write_index_screlease; +hsa_queue_cas_write_index_acq_rel = hsa_queue_cas_write_index_scacq_screl; +hsa_queue_cas_write_index_acquire = hsa_queue_cas_write_index_scacquire; +hsa_queue_cas_write_index_release = hsa_queue_cas_write_index_screlease; +hsa_queue_add_write_index_acq_rel = hsa_queue_add_write_index_scacq_screl; +hsa_queue_add_write_index_acquire = hsa_queue_add_write_index_scacquire; +hsa_queue_add_write_index_release = hsa_queue_add_write_index_screlease; +hsa_queue_store_read_index_release = hsa_queue_store_read_index_screlease; +hsa_signal_load_acquire = hsa_signal_load_scacquire; +hsa_signal_store_release = hsa_signal_store_screlease; +hsa_signal_wait_acquire = hsa_signal_wait_scacquire; +hsa_signal_and_acquire = hsa_signal_and_scacquire; +hsa_signal_and_release = hsa_signal_and_screlease; +hsa_signal_and_acq_rel = hsa_signal_and_scacq_screl; +hsa_signal_or_acquire = hsa_signal_or_scacquire; +hsa_signal_or_release = hsa_signal_or_screlease; +hsa_signal_or_acq_rel = hsa_signal_or_scacq_screl; +hsa_signal_xor_acquire = hsa_signal_xor_scacquire; +hsa_signal_xor_release = hsa_signal_xor_screlease; +hsa_signal_xor_acq_rel = hsa_signal_xor_scacq_screl; +hsa_signal_exchange_acquire = hsa_signal_exchange_scacquire; +hsa_signal_exchange_release = hsa_signal_exchange_screlease; +hsa_signal_exchange_acq_rel = hsa_signal_exchange_scacq_screl; +hsa_signal_add_acquire = hsa_signal_add_scacquire; +hsa_signal_add_release = hsa_signal_add_screlease; +hsa_signal_add_acq_rel = hsa_signal_add_scacq_screl; +hsa_signal_subtract_acquire = hsa_signal_subtract_scacquire; +hsa_signal_subtract_release = hsa_signal_subtract_screlease; +hsa_signal_subtract_acq_rel = hsa_signal_subtract_scacq_screl; +hsa_signal_cas_acquire = hsa_signal_cas_scacquire; +hsa_signal_cas_release = hsa_signal_cas_screlease; +hsa_signal_cas_acq_rel = hsa_signal_cas_scacq_screl; diff --git a/runtime/hsa-runtime/core/inc/agent.h b/runtime/hsa-runtime/core/inc/agent.h index 41867eb3c3..c0d41b827a 100644 --- a/runtime/hsa-runtime/core/inc/agent.h +++ b/runtime/hsa-runtime/core/inc/agent.h @@ -190,6 +190,9 @@ class Agent : public Checked<0xF6BC25EB17E6F917> { hsa_status_t (*callback)(hsa_region_t region, void* data), void* data) const = 0; + // @brief Invoke the callback for each cache useable by this agent. + virtual hsa_status_t IterateCache(hsa_status_t (*callback )(hsa_cache_t cache, void *data), void* data) const = 0; + // @brief Create queue. // // @param [in] size Number of packets the queue is expected to hold. Must be a diff --git a/runtime/hsa-runtime/core/inc/amd_cpu_agent.h b/runtime/hsa-runtime/core/inc/amd_cpu_agent.h index 4124371abf..19762bb87d 100644 --- a/runtime/hsa-runtime/core/inc/amd_cpu_agent.h +++ b/runtime/hsa-runtime/core/inc/amd_cpu_agent.h @@ -52,6 +52,7 @@ #include "core/inc/runtime.h" #include "core/inc/agent.h" #include "core/inc/queue.h" +#include "core/inc/cache.h" namespace amd { // @brief Class to represent a CPU device. @@ -88,6 +89,9 @@ class CpuAgent : public core::Agent { void* data), void* data) const override; + // @brief Override from core::Agent. + hsa_status_t IterateCache(hsa_status_t (*callback )(hsa_cache_t cache, void *data), void* value) const override; + // @brief Override from core::Agent. hsa_status_t GetInfo(hsa_agent_info_t attribute, void* value) const override; @@ -143,6 +147,9 @@ class CpuAgent : public core::Agent { // level. std::vector cache_props_; + // @brief Array of HSA cache objects. + std::vector> caches_; + // @brief Array of regions owned by this agent. std::vector regions_; diff --git a/runtime/hsa-runtime/core/inc/amd_gpu_agent.h b/runtime/hsa-runtime/core/inc/amd_gpu_agent.h index dea092ff87..a7c4f08570 100644 --- a/runtime/hsa-runtime/core/inc/amd_gpu_agent.h +++ b/runtime/hsa-runtime/core/inc/amd_gpu_agent.h @@ -53,6 +53,7 @@ #include "core/inc/agent.h" #include "core/inc/blit.h" #include "core/inc/signal.h" +#include "core/inc/cache.h" #include "core/util/small_heap.h" #include "core/util/locks.h" @@ -222,6 +223,9 @@ class GpuAgent : public GpuAgentInt { void* data), void* data) const override; + // @brief Override from core::Agent. + hsa_status_t IterateCache(hsa_status_t (*callback )(hsa_cache_t cache, void *data), void* value) const override; + // @brief Override from core::Agent. hsa_status_t DmaCopy(void* dst, const void* src, size_t size) override; @@ -402,6 +406,9 @@ class GpuAgent : public GpuAgentInt { // @brief Array of GPU cache property. std::vector cache_props_; + // @brief Array of HSA cache objects. + std::vector> caches_; + // @brief Array of regions owned by this agent. std::vector regions_; diff --git a/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp b/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp index 251df841ac..562456a63a 100644 --- a/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp +++ b/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp @@ -73,15 +73,10 @@ typedef uint32_t hsa_symbol_info32_t; typedef hsa_executable_symbol_t hsa_symbol_t; typedef hsa_executable_symbol_info_t hsa_symbol_info_t; -/// @brief Loaded code object handle. -typedef struct amd_loaded_code_object_s { - uint64_t handle; -} amd_loaded_code_object_t; - /// @brief Loaded code object attributes. -enum amd_loaded_code_object_info_t { - AMD_LOADED_CODE_OBJECT_INFO_ELF_IMAGE = 0, - AMD_LOADED_CODE_OBJECT_INFO_ELF_IMAGE_SIZE = 1 +enum hsa_loaded_code_object_info_t { + HSA_LOADED_CODE_OBJECT_INFO_ELF_IMAGE = 0, + HSA_LOADED_CODE_OBJECT_INFO_ELF_IMAGE_SIZE = 1 }; /// @brief Loaded segment handle. @@ -175,6 +170,8 @@ public: virtual bool GetInfo(hsa_symbol_info32_t symbol_info, void *value) = 0; + virtual hsa_agent_t GetAgent() = 0; + protected: Symbol() {} @@ -189,13 +186,13 @@ private: class LoadedCodeObject { public: - static amd_loaded_code_object_t Handle(LoadedCodeObject *object) { - amd_loaded_code_object_t handle = + static hsa_loaded_code_object_t Handle(LoadedCodeObject *object) { + hsa_loaded_code_object_t handle = {reinterpret_cast(object)}; return handle; } - static LoadedCodeObject* Object(amd_loaded_code_object_t handle) { + static LoadedCodeObject* Object(hsa_loaded_code_object_t handle) { LoadedCodeObject *object = reinterpret_cast(handle.handle); return object; @@ -203,7 +200,7 @@ public: virtual ~LoadedCodeObject() {} - virtual bool GetInfo(amd_loaded_code_object_info_t attribute, void *value) = 0; + virtual bool GetInfo(hsa_loaded_code_object_info_t attribute, void *value) = 0; virtual hsa_status_t IterateLoadedSegments( hsa_status_t (*callback)( @@ -285,24 +282,28 @@ public: hsa_agent_t agent, hsa_code_object_t code_object, const char *options, - amd_loaded_code_object_t *loaded_code_object = nullptr) = 0; + hsa_loaded_code_object_t *loaded_code_object = nullptr, + bool load_legacy = true) = 0; virtual hsa_status_t LoadCodeObject( hsa_agent_t agent, hsa_code_object_t code_object, size_t code_object_size, const char *options, - amd_loaded_code_object_t *loaded_code_object = nullptr) = 0; + hsa_loaded_code_object_t *loaded_code_object = nullptr, + bool load_legacy = true) = 0; virtual hsa_status_t Freeze(const char *options) = 0; virtual hsa_status_t Validate(uint32_t *result) = 0; + /// @note needed for hsa v1.0. + /// @todo remove during loader refactoring. + virtual bool IsProgramSymbol(const char *symbol_name) = 0; + virtual Symbol* GetSymbol( - const char *module_name, const char *symbol_name, - hsa_agent_t agent, - int32_t call_convention) = 0; + const hsa_agent_t *agent) = 0; typedef hsa_status_t (*iterate_symbols_f)( hsa_executable_t executable, @@ -312,9 +313,25 @@ public: virtual hsa_status_t IterateSymbols( iterate_symbols_f callback, void *data) = 0; + /// @since hsa v1.1. + virtual hsa_status_t IterateAgentSymbols( + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_agent_t agent, + hsa_executable_symbol_t symbol, + void *data), + void *data) = 0; + + /// @since hsa v1.1. + virtual hsa_status_t IterateProgramSymbols( + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_executable_symbol_t symbol, + void *data), + void *data) = 0; + virtual hsa_status_t IterateLoadedCodeObjects( hsa_status_t (*callback)( - amd_loaded_code_object_t loaded_code_object, + hsa_loaded_code_object_t loaded_code_object, void *data), void *data) = 0; @@ -364,7 +381,10 @@ public: /// @brief Creates empty AMD HSA Executable with specified @p profile, /// @p options - virtual Executable* CreateExecutable(hsa_profile_t profile, const char *options) = 0; + virtual Executable* CreateExecutable( + hsa_profile_t profile, + const char *options, + hsa_default_float_rounding_mode_t default_float_rounding_mode = HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT) = 0; /// @brief Destroys @p executable virtual void DestroyExecutable(Executable *executable) = 0; diff --git a/runtime/hsa-runtime/core/inc/cache.h b/runtime/hsa-runtime/core/inc/cache.h new file mode 100644 index 0000000000..1f0b6479be --- /dev/null +++ b/runtime/hsa-runtime/core/inc/cache.h @@ -0,0 +1,86 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// The University of Illinois/NCSA +// Open Source License (NCSA) +// +// Copyright (c) 2014-2015, Advanced Micro Devices, Inc. All rights reserved. +// +// Developed by: +// +// AMD Research and AMD HSA Software Development +// +// Advanced Micro Devices, Inc. +// +// www.amd.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal with the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimers. +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimers in +// the documentation and/or other materials provided with the distribution. +// - Neither the names of Advanced Micro Devices, Inc, +// nor the names of its contributors may be used to endorse or promote +// products derived from this Software without specific prior written +// permission. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS WITH THE SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef HSA_RUNTIME_CORE_INC_CACHE_H +#define HSA_RUNTIME_CORE_INC_CACHE_H + +#include "core/inc/hsa_internal.h" +#include "core/inc/checked.h" +#include "core/util/utils.h" +#include +#include + +namespace core +{ + + class Cache : public Checked<0x39A6C7AD3F135B06> + { + public: + static __forceinline hsa_cache_t Convert(const Cache* cache) + { + const hsa_cache_t handle={ static_cast(reinterpret_cast(cache)) }; + return handle; + } + static __forceinline Cache* Convert(const hsa_cache_t cache) + { + return reinterpret_cast(static_cast(cache.handle)); + } + + Cache(const std::string& name, uint8_t level, uint32_t size) : name_(name), level_(level), size_(size) {} + + Cache(std::string&& name, uint8_t level, uint32_t size) : name_(std::move(name)), level_(level), size_(size) {} + + hsa_status_t GetInfo(hsa_cache_info_t attribute, void* value); + + private: + + std::string name_; + uint32_t level_; + uint32_t size_; + + // Forbid copying and moving of this object + DISALLOW_COPY_AND_ASSIGN(Cache); + }; + +} + +#endif // HSA_RUNTIME_CORE_INC_CACHE_H diff --git a/runtime/hsa-runtime/core/inc/hsa_internal.h b/runtime/hsa-runtime/core/inc/hsa_internal.h index 6e3679a2c9..887a0ea22e 100644 --- a/runtime/hsa-runtime/core/inc/hsa_internal.h +++ b/runtime/hsa-runtime/core/inc/hsa_internal.h @@ -53,12 +53,16 @@ namespace HSA hsa_status_t HSA_API hsa_shut_down(); hsa_status_t HSA_API hsa_system_get_info(hsa_system_info_t attribute, void *value); + hsa_status_t HSA_API hsa_extension_get_name(uint16_t extension, const char **name); + hsa_status_t HSA_API hsa_system_extension_supported(uint16_t extension, uint16_t version_major, + uint16_t version_minor, bool* result); hsa_status_t HSA_API - hsa_system_extension_supported(uint16_t extension, uint16_t version_major, - uint16_t version_minor, bool *result); + hsa_system_major_extension_supported(uint16_t extension, uint16_t version_major, + uint16_t *version_minor, bool *result); hsa_status_t HSA_API hsa_system_get_extension_table(uint16_t extension, uint16_t version_major, uint16_t version_minor, void *table); + hsa_status_t HSA_API hsa_system_get_major_extension_table(uint16_t extension, uint16_t version_major, size_t table_length, void *table); hsa_status_t HSA_API hsa_iterate_agents(hsa_status_t (*callback)(hsa_agent_t agent, void *data), void *data); @@ -68,10 +72,13 @@ namespace HSA hsa_status_t HSA_API hsa_agent_get_exception_policies(hsa_agent_t agent, hsa_profile_t profile, uint16_t *mask); + hsa_status_t HSA_API hsa_cache_get_info(hsa_cache_t cache, hsa_cache_info_t attribute, void *value); + hsa_status_t HSA_API hsa_agent_iterate_caches(hsa_agent_t agent, hsa_status_t (*callback )(hsa_cache_t cache, void *data), void *value); 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); + hsa_status_t HSA_API hsa_agent_major_extension_supported(uint16_t extension, hsa_agent_t agent, uint16_t version_major, uint16_t *version_minor, bool *result); hsa_status_t HSA_API hsa_queue_create(hsa_agent_t agent, uint32_t size, hsa_queue_type_t type, void (*callback)(hsa_status_t status, hsa_queue_t *source, @@ -84,37 +91,37 @@ namespace HSA hsa_signal_t completion_signal, hsa_queue_t **queue); hsa_status_t HSA_API hsa_queue_destroy(hsa_queue_t *queue); hsa_status_t HSA_API hsa_queue_inactivate(hsa_queue_t *queue); - uint64_t HSA_API hsa_queue_load_read_index_acquire(const hsa_queue_t *queue); + uint64_t HSA_API hsa_queue_load_read_index_scacquire(const hsa_queue_t *queue); uint64_t HSA_API hsa_queue_load_read_index_relaxed(const hsa_queue_t *queue); - uint64_t HSA_API hsa_queue_load_write_index_acquire(const hsa_queue_t *queue); + uint64_t HSA_API hsa_queue_load_write_index_scacquire(const hsa_queue_t *queue); uint64_t HSA_API hsa_queue_load_write_index_relaxed(const hsa_queue_t *queue); void HSA_API hsa_queue_store_write_index_relaxed(const hsa_queue_t *queue, uint64_t value); - void HSA_API hsa_queue_store_write_index_release(const hsa_queue_t *queue, + void HSA_API hsa_queue_store_write_index_screlease(const hsa_queue_t *queue, uint64_t value); - uint64_t HSA_API hsa_queue_cas_write_index_acq_rel(const hsa_queue_t *queue, + uint64_t HSA_API hsa_queue_cas_write_index_scacq_screl(const hsa_queue_t *queue, uint64_t expected, uint64_t value); - uint64_t HSA_API hsa_queue_cas_write_index_acquire(const hsa_queue_t *queue, + uint64_t HSA_API hsa_queue_cas_write_index_scacquire(const hsa_queue_t *queue, uint64_t expected, uint64_t value); uint64_t HSA_API hsa_queue_cas_write_index_relaxed(const hsa_queue_t *queue, uint64_t expected, uint64_t value); - uint64_t HSA_API hsa_queue_cas_write_index_release(const hsa_queue_t *queue, + uint64_t HSA_API hsa_queue_cas_write_index_screlease(const hsa_queue_t *queue, uint64_t expected, uint64_t value); uint64_t HSA_API - hsa_queue_add_write_index_acq_rel(const hsa_queue_t *queue, uint64_t value); + hsa_queue_add_write_index_scacq_screl(const hsa_queue_t *queue, uint64_t value); uint64_t HSA_API - hsa_queue_add_write_index_acquire(const hsa_queue_t *queue, uint64_t value); + hsa_queue_add_write_index_scacquire(const hsa_queue_t *queue, uint64_t value); uint64_t HSA_API hsa_queue_add_write_index_relaxed(const hsa_queue_t *queue, uint64_t value); uint64_t HSA_API - hsa_queue_add_write_index_release(const hsa_queue_t *queue, uint64_t value); + hsa_queue_add_write_index_screlease(const hsa_queue_t *queue, uint64_t value); void HSA_API hsa_queue_store_read_index_relaxed(const hsa_queue_t *queue, uint64_t value); - void HSA_API hsa_queue_store_read_index_release(const hsa_queue_t *queue, + void HSA_API hsa_queue_store_read_index_screlease(const hsa_queue_t *queue, uint64_t value); hsa_status_t HSA_API hsa_agent_iterate_regions( hsa_agent_t agent, @@ -135,11 +142,13 @@ namespace HSA const hsa_agent_t *consumers, hsa_signal_t *signal); hsa_status_t HSA_API hsa_signal_destroy(hsa_signal_t signal); hsa_signal_value_t HSA_API hsa_signal_load_relaxed(hsa_signal_t signal); - hsa_signal_value_t HSA_API hsa_signal_load_acquire(hsa_signal_t signal); + hsa_signal_value_t HSA_API hsa_signal_load_scacquire(hsa_signal_t signal); void HSA_API hsa_signal_store_relaxed(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_store_release(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_store_screlease(hsa_signal_t signal, hsa_signal_value_t value); + void HSA_API hsa_signal_silent_store_relaxed(hsa_signal_t signal, hsa_signal_value_t value); + void HSA_API hsa_signal_silent_store_screlease(hsa_signal_t signal, hsa_signal_value_t value); hsa_signal_value_t HSA_API hsa_signal_wait_relaxed(hsa_signal_t signal, hsa_signal_condition_t condition, @@ -147,195 +156,269 @@ namespace HSA uint64_t timeout_hint, hsa_wait_state_t wait_expectancy_hint); hsa_signal_value_t HSA_API - hsa_signal_wait_acquire(hsa_signal_t signal, + hsa_signal_wait_scacquire(hsa_signal_t signal, hsa_signal_condition_t condition, hsa_signal_value_t compare_value, uint64_t timeout_hint, hsa_wait_state_t wait_expectancy_hint); + hsa_status_t HSA_API hsa_signal_group_create(uint32_t num_signals, const hsa_signal_t *signals, uint32_t num_consumers, const hsa_agent_t *consumers, hsa_signal_group_t *signal_group); + hsa_status_t HSA_API hsa_signal_group_destroy(hsa_signal_group_t signal_group); + hsa_status_t HSA_API hsa_signal_group_wait_any_scacquire(hsa_signal_group_t signal_group, const hsa_signal_condition_t *conditions, const hsa_signal_value_t *compare_values, hsa_wait_state_t wait_state_hint, hsa_signal_t *signal, hsa_signal_value_t *value); + hsa_status_t HSA_API hsa_signal_group_wait_any_relaxed(hsa_signal_group_t signal_group, const hsa_signal_condition_t *conditions, const hsa_signal_value_t *compare_values, hsa_wait_state_t wait_state_hint, hsa_signal_t *signal, hsa_signal_value_t *value); void HSA_API hsa_signal_and_relaxed(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_and_acquire(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_and_scacquire(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_and_release(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_and_screlease(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_and_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_and_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API hsa_signal_or_relaxed(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_or_acquire(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_or_scacquire(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_or_release(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_or_screlease(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_or_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_or_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API hsa_signal_xor_relaxed(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_xor_acquire(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_xor_scacquire(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_xor_release(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_xor_screlease(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_xor_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_xor_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API hsa_signal_add_relaxed(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_add_acquire(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_add_scacquire(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_add_release(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_add_screlease(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_add_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_add_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API hsa_signal_subtract_relaxed(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_subtract_acquire(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_subtract_scacquire(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_subtract_release(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_subtract_screlease(hsa_signal_t signal, hsa_signal_value_t value); void HSA_API - hsa_signal_subtract_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_subtract_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value); hsa_signal_value_t HSA_API hsa_signal_exchange_relaxed(hsa_signal_t signal, hsa_signal_value_t value); hsa_signal_value_t HSA_API - hsa_signal_exchange_acquire(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_exchange_scacquire(hsa_signal_t signal, hsa_signal_value_t value); hsa_signal_value_t HSA_API - hsa_signal_exchange_release(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_exchange_screlease(hsa_signal_t signal, hsa_signal_value_t value); hsa_signal_value_t HSA_API - hsa_signal_exchange_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); + hsa_signal_exchange_scacq_screl(hsa_signal_t signal, hsa_signal_value_t value); hsa_signal_value_t HSA_API hsa_signal_cas_relaxed(hsa_signal_t signal, hsa_signal_value_t expected, hsa_signal_value_t value); - hsa_signal_value_t HSA_API hsa_signal_cas_acquire(hsa_signal_t signal, + hsa_signal_value_t HSA_API hsa_signal_cas_scacquire(hsa_signal_t signal, hsa_signal_value_t expected, hsa_signal_value_t value); - hsa_signal_value_t HSA_API hsa_signal_cas_release(hsa_signal_t signal, + hsa_signal_value_t HSA_API hsa_signal_cas_screlease(hsa_signal_t signal, hsa_signal_value_t expected, hsa_signal_value_t value); - hsa_signal_value_t HSA_API hsa_signal_cas_acq_rel(hsa_signal_t signal, + hsa_signal_value_t HSA_API hsa_signal_cas_scacq_screl(hsa_signal_t signal, hsa_signal_value_t expected, hsa_signal_value_t value); - hsa_status_t hsa_isa_from_name( - const char *name, - hsa_isa_t *isa - ); - hsa_status_t HSA_API hsa_isa_get_info( - hsa_isa_t isa, - hsa_isa_info_t attribute, - uint32_t index, - void *value - ); - hsa_status_t hsa_isa_compatible( - hsa_isa_t code_object_isa, - hsa_isa_t agent_isa, - bool *result - ); - hsa_status_t HSA_API hsa_code_object_serialize( - hsa_code_object_t code_object, - hsa_status_t (*alloc_callback)( - size_t size, hsa_callback_data_t data, void **address - ), - hsa_callback_data_t callback_data, - const char *options, - void **serialized_code_object, - size_t *serialized_code_object_size - ); - hsa_status_t HSA_API hsa_code_object_deserialize( - void *serialized_code_object, - size_t serialized_code_object_size, - const char *options, - hsa_code_object_t *code_object - ); - hsa_status_t HSA_API hsa_code_object_destroy( - hsa_code_object_t code_object - ); - hsa_status_t HSA_API hsa_code_object_get_info( - hsa_code_object_t code_object, - hsa_code_object_info_t attribute, - void *value - ); - hsa_status_t HSA_API hsa_code_object_get_symbol( - hsa_code_object_t code_object, - const char *symbol_name, - hsa_code_symbol_t *symbol - ); - hsa_status_t HSA_API hsa_code_symbol_get_info( - hsa_code_symbol_t code_symbol, - hsa_code_symbol_info_t attribute, - void *value - ); - hsa_status_t HSA_API hsa_code_object_iterate_symbols( - hsa_code_object_t code_object, - hsa_status_t (*callback)( - hsa_code_object_t code_object, hsa_code_symbol_t symbol, void *data - ), - void *data - ); - hsa_status_t HSA_API hsa_executable_create( - hsa_profile_t profile, - hsa_executable_state_t executable_state, - const char *options, - hsa_executable_t *executable - ); - hsa_status_t HSA_API hsa_executable_destroy( - hsa_executable_t executable - ); - hsa_status_t HSA_API hsa_executable_load_code_object( - hsa_executable_t executable, - hsa_agent_t agent, - hsa_code_object_t code_object, - const char *options - ); - hsa_status_t HSA_API hsa_executable_freeze( - hsa_executable_t executable, - const char *options - ); - hsa_status_t HSA_API hsa_executable_get_info( - hsa_executable_t executable, - hsa_executable_info_t attribute, - void *value - ); - hsa_status_t HSA_API hsa_executable_global_variable_define( - hsa_executable_t executable, - const char *variable_name, - void *address - ); - hsa_status_t HSA_API hsa_executable_agent_global_variable_define( - hsa_executable_t executable, - hsa_agent_t agent, - const char *variable_name, - void *address - ); - hsa_status_t HSA_API hsa_executable_readonly_variable_define( - hsa_executable_t executable, - hsa_agent_t agent, - const char *variable_name, - void *address - ); - hsa_status_t HSA_API hsa_executable_validate( - hsa_executable_t executable, - uint32_t *result - ); - hsa_status_t HSA_API hsa_executable_get_symbol( - hsa_executable_t executable, - const char *module_name, - const char *symbol_name, - hsa_agent_t agent, - int32_t call_convention, - hsa_executable_symbol_t *symbol - ); - hsa_status_t HSA_API hsa_executable_symbol_get_info( - hsa_executable_symbol_t executable_symbol, - hsa_executable_symbol_info_t attribute, - void *value - ); - hsa_status_t HSA_API hsa_executable_iterate_symbols( - hsa_executable_t executable, - hsa_status_t (*callback)( - hsa_executable_t executable, hsa_executable_symbol_t symbol, void *data - ), - void *data - ); - hsa_status_t HSA_API - hsa_status_string(hsa_status_t status, const char **status_string); + //===--- Instruction Set Architecture -----------------------------------===// + + hsa_status_t HSA_API hsa_isa_from_name( + const char *name, + hsa_isa_t *isa); + hsa_status_t HSA_API hsa_agent_iterate_isas( + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_isa_t isa, + void *data), + void *data); + /* deprecated */ hsa_status_t HSA_API hsa_isa_get_info( + hsa_isa_t isa, + hsa_isa_info_t attribute, + uint32_t index, + void *value); + hsa_status_t HSA_API hsa_isa_get_info_alt( + hsa_isa_t isa, + hsa_isa_info_t attribute, + void *value); + hsa_status_t HSA_API hsa_isa_get_exception_policies( + hsa_isa_t isa, + hsa_profile_t profile, + uint16_t *mask); + hsa_status_t HSA_API hsa_isa_get_round_method( + hsa_isa_t isa, + hsa_fp_type_t fp_type, + hsa_flush_mode_t flush_mode, + hsa_round_method_t *round_method); + hsa_status_t HSA_API hsa_wavefront_get_info( + hsa_wavefront_t wavefront, + hsa_wavefront_info_t attribute, + void *value); + hsa_status_t HSA_API hsa_isa_iterate_wavefronts( + hsa_isa_t isa, + hsa_status_t (*callback)(hsa_wavefront_t wavefront, + void *data), + void *data); + /* deprecated */ hsa_status_t HSA_API hsa_isa_compatible( + hsa_isa_t code_object_isa, + hsa_isa_t agent_isa, + bool *result); + + //===--- Code Objects (deprecated) --------------------------------------===// + + /* deprecated */ hsa_status_t HSA_API hsa_code_object_serialize( + hsa_code_object_t code_object, + hsa_status_t (*alloc_callback)(size_t size, + hsa_callback_data_t data, + void **address), + hsa_callback_data_t callback_data, + const char *options, + void **serialized_code_object, + size_t *serialized_code_object_size); + /* deprecated */ hsa_status_t HSA_API hsa_code_object_deserialize( + void *serialized_code_object, + size_t serialized_code_object_size, + const char *options, + hsa_code_object_t *code_object); + /* deprecated */ hsa_status_t HSA_API hsa_code_object_destroy( + hsa_code_object_t code_object); + /* deprecated */ hsa_status_t HSA_API hsa_code_object_get_info( + hsa_code_object_t code_object, + hsa_code_object_info_t attribute, + void *value); + /* deprecated */ hsa_status_t HSA_API hsa_code_object_get_symbol( + hsa_code_object_t code_object, + const char *symbol_name, + hsa_code_symbol_t *symbol); + /* deprecated */ hsa_status_t HSA_API hsa_code_object_get_symbol_from_name( + hsa_code_object_t code_object, + const char *module_name, + const char *symbol_name, + hsa_code_symbol_t *symbol); + /* deprecated */ hsa_status_t HSA_API hsa_code_symbol_get_info( + hsa_code_symbol_t code_symbol, + hsa_code_symbol_info_t attribute, + void *value); + /* deprecated */ hsa_status_t HSA_API hsa_code_object_iterate_symbols( + hsa_code_object_t code_object, + hsa_status_t (*callback)(hsa_code_object_t code_object, + hsa_code_symbol_t symbol, + void *data), + void *data); + + //===--- Executable -----------------------------------------------------===// + + hsa_status_t HSA_API hsa_code_object_reader_create_from_file( + hsa_file_t file, + hsa_code_object_reader_t *code_object_reader); + hsa_status_t HSA_API hsa_code_object_reader_create_from_memory( + const void *code_object, + size_t size, + hsa_code_object_reader_t *code_object_reader); + hsa_status_t HSA_API hsa_code_object_reader_destroy( + hsa_code_object_reader_t code_object_reader); + /* deprecated */ hsa_status_t HSA_API hsa_executable_create( + hsa_profile_t profile, + hsa_executable_state_t executable_state, + const char *options, + hsa_executable_t *executable); + hsa_status_t HSA_API hsa_executable_create_alt( + hsa_profile_t profile, + hsa_default_float_rounding_mode_t default_float_rounding_mode, + const char *options, + hsa_executable_t *executable); + hsa_status_t HSA_API hsa_executable_destroy( + hsa_executable_t executable); + /* deprecated */ hsa_status_t HSA_API hsa_executable_load_code_object( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_code_object_t code_object, + const char *options); + hsa_status_t HSA_API hsa_executable_load_program_code_object( + hsa_executable_t executable, + hsa_code_object_reader_t code_object_reader, + const char *options, + hsa_loaded_code_object_t *loaded_code_object); + hsa_status_t HSA_API hsa_executable_load_agent_code_object( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_code_object_reader_t code_object_reader, + const char *options, + hsa_loaded_code_object_t *loaded_code_object); + hsa_status_t HSA_API hsa_executable_freeze( + hsa_executable_t executable, + const char *options); + hsa_status_t HSA_API hsa_executable_get_info( + hsa_executable_t executable, + hsa_executable_info_t attribute, + void *value); + hsa_status_t HSA_API hsa_executable_global_variable_define( + hsa_executable_t executable, + const char *variable_name, + void *address); + hsa_status_t HSA_API hsa_executable_agent_global_variable_define( + hsa_executable_t executable, + hsa_agent_t agent, + const char *variable_name, + void *address); + hsa_status_t HSA_API hsa_executable_readonly_variable_define( + hsa_executable_t executable, + hsa_agent_t agent, + const char *variable_name, + void *address); + hsa_status_t HSA_API hsa_executable_validate( + hsa_executable_t executable, + uint32_t *result); + hsa_status_t HSA_API hsa_executable_validate_alt( + hsa_executable_t executable, + const char *options, + uint32_t *result); + /* deprecated */ hsa_status_t HSA_API hsa_executable_get_symbol( + hsa_executable_t executable, + const char *module_name, + const char *symbol_name, + hsa_agent_t agent, + int32_t call_convention, + hsa_executable_symbol_t *symbol); + hsa_status_t HSA_API hsa_executable_get_symbol_by_name( + hsa_executable_t executable, + const char *symbol_name, + const hsa_agent_t *agent, + hsa_executable_symbol_t *symbol); + hsa_status_t HSA_API hsa_executable_symbol_get_info( + hsa_executable_symbol_t executable_symbol, + hsa_executable_symbol_info_t attribute, + void *value); + /* deprecated */ hsa_status_t HSA_API hsa_executable_iterate_symbols( + hsa_executable_t executable, + hsa_status_t (*callback)(hsa_executable_t executable, + hsa_executable_symbol_t symbol, + void *data), + void *data); + hsa_status_t HSA_API hsa_executable_iterate_agent_symbols( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_agent_t agent, + hsa_executable_symbol_t symbol, + void *data), + void *data); + hsa_status_t HSA_API hsa_executable_iterate_program_symbols( + hsa_executable_t executable, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_executable_symbol_t symbol, + void *data), + void *data); + + //===--- Runtime Notifications ------------------------------------------===// + + hsa_status_t HSA_API hsa_status_string( + hsa_status_t status, + const char **status_string); } #ifdef BUILDING_HSA_CORE_RUNTIME diff --git a/runtime/hsa-runtime/core/inc/isa.h b/runtime/hsa-runtime/core/inc/isa.h index fe026f60e5..f2c224f2ff 100644 --- a/runtime/hsa-runtime/core/inc/isa.h +++ b/runtime/hsa-runtime/core/inc/isa.h @@ -52,6 +52,35 @@ namespace core { +/// @class Wavefront. +/// @brief Wavefront. +class Wavefront final: public amd::hsa::common::Signed<0xA02483F1AD7F101C> { +public: + /// @brief Default destructor. + ~Wavefront() {} + + /// @returns Handle equivalent of @p object. + static hsa_wavefront_t Handle(const Wavefront *object) { + hsa_wavefront_t handle = { reinterpret_cast(object) }; + return handle; + } + /// @returns Object equivalent of @p handle. + static Wavefront *Object(const hsa_wavefront_t &handle) { + Wavefront *object = amd::hsa::common::ObjectAt(handle.handle); + return object; + } + + /// @brief Query value of requested @p attribute and record it in @p value. + bool GetInfo(const hsa_wavefront_info_t &attribute, void *value) const; + +private: + /// @brief Default constructor. + Wavefront() {} + + /// @brief Wavefront's friends. + friend class Isa; +}; + /// @class Isa. /// @brief Instruction Set Architecture. class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> { @@ -67,7 +96,7 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> { hsa_isa_t isa_handle = { reinterpret_cast(isa_object) }; return isa_handle; } - /// @returns Object equivalend of @p isa_handle. + /// @returns Object equivalent of @p isa_handle. static Isa *Object(const hsa_isa_t &isa_handle) { Isa *isa_object = amd::hsa::common::ObjectAt(isa_handle.handle); return isa_object; @@ -77,6 +106,10 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> { const Version &version() const { return version_; } + /// @returns This Isa's supported wavefront. + const Wavefront &wavefront() const { + return wavefront_; + } /// @returns This Isa's vendor. std::string GetVendor() const { @@ -98,6 +131,10 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> { int32_t GetStepping() const { return std::get<2>(version_); } + /// @returns Pointer to this Isa's supported wavefront. + const Wavefront *GetWavefront() const { + return &wavefront_; + } /// @returns True if this Isa is compatible with @p isa_object, false /// otherwise. @@ -122,6 +159,13 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> { /// @brief Query value of requested @p attribute and record it in @p value. bool GetInfo(const hsa_isa_info_t &attribute, void *value) const; + /// @returns Round method (single or double) used to implement the floating- + /// point multiply add instruction (mad) for a given combination of @p fp_type + /// and @p flush_mode. + hsa_round_method_t GetRoundMethod( + hsa_fp_type_t fp_type, + hsa_flush_mode_t flush_mode) const; + private: /// @brief Default constructor. Isa(): version_(Version(-1, -1, -1)) {} @@ -132,6 +176,9 @@ class Isa final: public amd::hsa::common::Signed<0xB13594F2BD8F212D> { /// @brief Isa's version. Version version_; + /// @brief Isa's supported wavefront. + Wavefront wavefront_; + /// @brief Isa's friends. friend class IsaRegistry; }; // class Isa diff --git a/runtime/hsa-runtime/core/inc/queue.h b/runtime/hsa-runtime/core/inc/queue.h index bc31c7b579..0c3aceca1a 100644 --- a/runtime/hsa-runtime/core/inc/queue.h +++ b/runtime/hsa-runtime/core/inc/queue.h @@ -90,11 +90,11 @@ struct AqlPacket { << "\nbarrier: " << ((dispatch.header >> HSA_PACKET_HEADER_BARRIER) & ((1 << HSA_PACKET_HEADER_WIDTH_BARRIER) - 1)) << "\nacquire: " - << ((dispatch.header >> HSA_PACKET_HEADER_ACQUIRE_FENCE_SCOPE) & - ((1 << HSA_PACKET_HEADER_WIDTH_ACQUIRE_FENCE_SCOPE) - 1)) + << ((dispatch.header >> HSA_PACKET_HEADER_SCACQUIRE_FENCE_SCOPE) & + ((1 << HSA_PACKET_HEADER_WIDTH_SCACQUIRE_FENCE_SCOPE) - 1)) << "\nrelease: " - << ((dispatch.header >> HSA_PACKET_HEADER_RELEASE_FENCE_SCOPE) & - ((1 << HSA_PACKET_HEADER_WIDTH_RELEASE_FENCE_SCOPE) - 1)); + << ((dispatch.header >> HSA_PACKET_HEADER_SCRELEASE_FENCE_SCOPE) & + ((1 << HSA_PACKET_HEADER_WIDTH_SCRELEASE_FENCE_SCOPE) - 1)); if (type == HSA_PACKET_TYPE_KERNEL_DISPATCH) { string << "\nDim: " << dispatch.setup diff --git a/runtime/hsa-runtime/core/inc/signal.h b/runtime/hsa-runtime/core/inc/signal.h index 478034951f..171fd8afce 100644 --- a/runtime/hsa-runtime/core/inc/signal.h +++ b/runtime/hsa-runtime/core/inc/signal.h @@ -209,9 +209,9 @@ class Signal : public Checked<0x71FCCA6A3D5D5276>, /// timeout is reached. /// Returns the index of a satisfied signal. Returns -1 on timeout and /// errors. - static uint32_t WaitAny(uint32_t signal_count, hsa_signal_t* hsa_signals, - hsa_signal_condition_t* conds, - hsa_signal_value_t* values, uint64_t timeout_hint, + static uint32_t WaitAny(uint32_t signal_count, const hsa_signal_t* hsa_signals, + const hsa_signal_condition_t* conds, + const hsa_signal_value_t* values, uint64_t timeout_hint, hsa_wait_state_t wait_hint, hsa_signal_value_t* satisfying_value); @@ -277,5 +277,28 @@ static_assert( sizeof(hsa_signal_handle[2]) == sizeof(hsa_signal_t[2]), "hsa_signal_handle and hsa_signal_t must have identical binary layout."); +class SignalGroup : public Checked<0xBD35DDDD578F091> +{ +public: + static __forceinline hsa_signal_group_t Convert(SignalGroup* group) { const hsa_signal_group_t handle = { static_cast(reinterpret_cast(group)) }; return handle; } + static __forceinline SignalGroup* Convert(hsa_signal_group_t group) { return reinterpret_cast(static_cast(group.handle)); } + + SignalGroup(uint32_t num_signals, const hsa_signal_t* signals); + ~SignalGroup() { delete[] signals; } + + bool IsValid() const { + if (CheckedType::IsValid() && signals!=NULL) return true; + return false; + } + + const hsa_signal_t* List() const { return signals; } + uint32_t Count() const { return count; } + +private: + hsa_signal_t* signals; + const uint32_t count; + DISALLOW_COPY_AND_ASSIGN(SignalGroup); +}; + } // namespace core #endif // header guard diff --git a/runtime/hsa-runtime/core/runtime/amd_blit_kernel.cpp b/runtime/hsa-runtime/core/runtime/amd_blit_kernel.cpp index 1db1f4455a..e8f0f9f070 100644 --- a/runtime/hsa-runtime/core/runtime/amd_blit_kernel.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_blit_kernel.cpp @@ -603,7 +603,7 @@ hsa_status_t BlitKernel::SubmitLinearCopyCommand(void* dst, const void* src, } // Wait for the packet to finish. - if (HSA::hsa_signal_wait_acquire(completion_signal_, HSA_SIGNAL_CONDITION_LT, + if (HSA::hsa_signal_wait_scacquire(completion_signal_, HSA_SIGNAL_CONDITION_LT, 1, uint64_t(-1), HSA_WAIT_STATE_ACTIVE) != 0) { // Signal wait returned unexpected value. @@ -627,8 +627,8 @@ hsa_status_t BlitKernel::SubmitLinearCopyCommand( const uint16_t kBarrierPacketHeader = (HSA_PACKET_TYPE_BARRIER_AND << HSA_PACKET_HEADER_TYPE) | (1 << HSA_PACKET_HEADER_BARRIER) | - (HSA_FENCE_SCOPE_NONE << HSA_PACKET_HEADER_ACQUIRE_FENCE_SCOPE) | - (HSA_FENCE_SCOPE_AGENT << HSA_PACKET_HEADER_RELEASE_FENCE_SCOPE); + (HSA_FENCE_SCOPE_NONE << HSA_PACKET_HEADER_SCACQUIRE_FENCE_SCOPE) | + (HSA_FENCE_SCOPE_AGENT << HSA_PACKET_HEADER_SCRELEASE_FENCE_SCOPE); hsa_barrier_and_packet_t barrier_packet = {0}; barrier_packet.header = HSA_PACKET_TYPE_INVALID; @@ -766,7 +766,7 @@ hsa_status_t BlitKernel::SubmitLinearFillCommand(void* ptr, uint32_t value, ReleaseWriteIndex(write_index, 1); // Wait for the packet to finish. - if (HSA::hsa_signal_wait_acquire(completion_signal_, HSA_SIGNAL_CONDITION_LT, + if (HSA::hsa_signal_wait_scacquire(completion_signal_, HSA_SIGNAL_CONDITION_LT, 1, uint64_t(-1), HSA_WAIT_STATE_ACTIVE) != 0) { // Signal wait returned unexpected value. @@ -813,8 +813,8 @@ hsa_status_t BlitKernel::FenceRelease(uint64_t write_index, const uint16_t kBarrierPacketHeader = (HSA_PACKET_TYPE_BARRIER_AND << HSA_PACKET_HEADER_TYPE) | (1 << HSA_PACKET_HEADER_BARRIER) | - (HSA_FENCE_SCOPE_NONE << HSA_PACKET_HEADER_ACQUIRE_FENCE_SCOPE) | - (fence << HSA_PACKET_HEADER_RELEASE_FENCE_SCOPE); + (HSA_FENCE_SCOPE_NONE << HSA_PACKET_HEADER_SCACQUIRE_FENCE_SCOPE) | + (fence << HSA_PACKET_HEADER_SCRELEASE_FENCE_SCOPE); hsa_barrier_and_packet_t packet = {0}; packet.header = kInvalidPacketHeader; @@ -842,7 +842,7 @@ hsa_status_t BlitKernel::FenceRelease(uint64_t write_index, ReleaseWriteIndex(write_index, num_copy_packet + 1); // Wait for the packet to finish. - if (HSA::hsa_signal_wait_acquire(packet.completion_signal, + if (HSA::hsa_signal_wait_scacquire(packet.completion_signal, HSA_SIGNAL_CONDITION_LT, 1, uint64_t(-1), HSA_WAIT_STATE_ACTIVE) != 0) { // Signal wait returned unexpected value. @@ -862,8 +862,8 @@ void BlitKernel::PopulateQueue(uint64_t index, uint64_t code_handle, void* args, static const uint16_t kDispatchPacketHeader = (HSA_PACKET_TYPE_KERNEL_DISPATCH << HSA_PACKET_HEADER_TYPE) | (((completion_signal.handle != 0) ? 1 : 0) << HSA_PACKET_HEADER_BARRIER) | - (HSA_FENCE_SCOPE_SYSTEM << HSA_PACKET_HEADER_ACQUIRE_FENCE_SCOPE) | - (HSA_FENCE_SCOPE_SYSTEM << HSA_PACKET_HEADER_RELEASE_FENCE_SCOPE); + (HSA_FENCE_SCOPE_SYSTEM << HSA_PACKET_HEADER_SCACQUIRE_FENCE_SCOPE) | + (HSA_FENCE_SCOPE_SYSTEM << HSA_PACKET_HEADER_SCRELEASE_FENCE_SCOPE); packet.header = kInvalidPacketHeader; packet.kernel_object = code_handle; diff --git a/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp index 62cb62bdbd..5bfc0378ac 100644 --- a/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp @@ -125,6 +125,15 @@ void CpuAgent::InitCacheList() { } } } + + //Update cache objects + caches_.clear(); + caches_.resize(cache_props_.size()); + char name[64]; + GetInfo(HSA_AGENT_INFO_NAME, name); + std::string deviceName=name; + for(size_t i=0; i *data_pair = (std::pair*)data; + assert(data_pair); + assert(data_pair->first.handle != 0); + assert(data_pair->second != true); + + const core::Isa *isa1 = core::Isa::Object(isa); + assert(isa1); + const core::Isa *isa2 = core::Isa::Object(data_pair->first); + assert(isa2); + if (isa1->version() == isa2->version()) { + data_pair->second = true; + return HSA_STATUS_INFO_BREAK; + } + + return HSA_STATUS_SUCCESS; +} + } // namespace anonymous namespace amd { @@ -392,25 +412,14 @@ hsa_isa_t LoaderContext::IsaFromName(const char *name) { bool LoaderContext::IsaSupportedByAgent(hsa_agent_t agent, hsa_isa_t code_object_isa) { - assert(agent.handle); + assert(agent.handle != 0); - hsa_status_t hsa_status = HSA_STATUS_SUCCESS; - hsa_isa_t agent_isa; - agent_isa.handle = 0; - - hsa_status = HSA::hsa_agent_get_info(agent, HSA_AGENT_INFO_ISA, &agent_isa); - if (HSA_STATUS_SUCCESS != hsa_status) { + std::pair data(code_object_isa, false); + hsa_status_t status = HSA::hsa_agent_iterate_isas(agent, IsIsaEquivalent, &data); + if (status != HSA_STATUS_SUCCESS && status != HSA_STATUS_INFO_BREAK) { return false; } - - bool result = false; - - hsa_status = HSA::hsa_isa_compatible(code_object_isa, agent_isa, &result); - if (HSA_STATUS_SUCCESS != hsa_status) { - return false; - } - - return result; + return data.second; } void* LoaderContext::SegmentAlloc(amdgpu_hsa_elf_segment_t segment, @@ -421,14 +430,16 @@ void* LoaderContext::SegmentAlloc(amdgpu_hsa_elf_segment_t segment, { assert(0 < size); assert(0 < align && 0 == (align & (align - 1))); - hsa_profile_t agent_profile; - if (HSA_STATUS_SUCCESS != HSA::hsa_agent_get_info(agent, HSA_AGENT_INFO_PROFILE, &agent_profile)) { - return nullptr; - } + SegmentMemory *mem = nullptr; switch (segment) { case AMDGPU_HSA_SEGMENT_GLOBAL_AGENT: - case AMDGPU_HSA_SEGMENT_READONLY_AGENT: + case AMDGPU_HSA_SEGMENT_READONLY_AGENT: { + hsa_profile_t agent_profile; + if (HSA_STATUS_SUCCESS != HSA::hsa_agent_get_info(agent, HSA_AGENT_INFO_PROFILE, &agent_profile)) { + return nullptr; + } + switch (agent_profile) { case HSA_PROFILE_BASE: mem = new (std::nothrow) RegionMemory(RegionMemory::AgentLocal(agent)); @@ -440,19 +451,17 @@ void* LoaderContext::SegmentAlloc(amdgpu_hsa_elf_segment_t segment, assert(false); } break; - case AMDGPU_HSA_SEGMENT_GLOBAL_PROGRAM: - switch (agent_profile) { - case HSA_PROFILE_BASE: - mem = new (std::nothrow) RegionMemory(RegionMemory::System()); - break; - case HSA_PROFILE_FULL: - mem = new (std::nothrow) MallocedMemory(); - break; - default: - assert(false); - } + } + case AMDGPU_HSA_SEGMENT_GLOBAL_PROGRAM: { + mem = new (std::nothrow) RegionMemory(RegionMemory::System()); break; - case AMDGPU_HSA_SEGMENT_CODE_AGENT: + } + case AMDGPU_HSA_SEGMENT_CODE_AGENT: { + hsa_profile_t agent_profile; + if (HSA_STATUS_SUCCESS != HSA::hsa_agent_get_info(agent, HSA_AGENT_INFO_PROFILE, &agent_profile)) { + return nullptr; + } + switch (agent_profile) { case HSA_PROFILE_BASE: mem = new (std::nothrow) RegionMemory(IsDebuggerRegistered() ? @@ -470,16 +479,20 @@ void* LoaderContext::SegmentAlloc(amdgpu_hsa_elf_segment_t segment, ((GpuAgentInt*)core::Agent::Convert(agent))->InvalidateCodeCaches(); break; + } default: assert(false); } + if (nullptr == mem) { return nullptr; } + if (!mem->Allocate(size, align, zero)) { delete mem; return nullptr; } + return mem; } diff --git a/runtime/hsa-runtime/core/runtime/cache.cpp b/runtime/hsa-runtime/core/runtime/cache.cpp new file mode 100644 index 0000000000..04e199aed2 --- /dev/null +++ b/runtime/hsa-runtime/core/runtime/cache.cpp @@ -0,0 +1,71 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// The University of Illinois/NCSA +// Open Source License (NCSA) +// +// Copyright (c) 2014-2015, Advanced Micro Devices, Inc. All rights reserved. +// +// Developed by: +// +// AMD Research and AMD HSA Software Development +// +// Advanced Micro Devices, Inc. +// +// www.amd.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal with the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimers. +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimers in +// the documentation and/or other materials provided with the distribution. +// - Neither the names of Advanced Micro Devices, Inc, +// nor the names of its contributors may be used to endorse or promote +// products derived from this Software without specific prior written +// permission. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS WITH THE SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + +#include "core/inc/cache.h" +#include "assert.h" + +namespace core +{ + + hsa_status_t Cache::GetInfo(hsa_cache_info_t attribute, void* value) + { + switch(attribute) + { + case HSA_CACHE_INFO_NAME_LENGTH: + *(uint32_t*)value=name_.size(); + break; + case HSA_CACHE_INFO_NAME: + *(const char**)value=name_.c_str(); + break; + case HSA_CACHE_INFO_LEVEL: + *(uint8_t*)value=level_; + break; + case HSA_CACHE_INFO_SIZE: + *(uint32_t*)value=size_; + break; + default: + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + return HSA_STATUS_SUCCESS; + } + +} diff --git a/runtime/hsa-runtime/core/runtime/hsa.cpp b/runtime/hsa-runtime/core/runtime/hsa.cpp index fdda3cf61b..e6acd09ef9 100644 --- a/runtime/hsa-runtime/core/runtime/hsa.cpp +++ b/runtime/hsa-runtime/core/runtime/hsa.cpp @@ -42,8 +42,21 @@ // HSA C to C++ interface implementation. // This file does argument checking and conversion to C++. +#include #include #include +#include +#include + +#if defined(_WIN32) || defined(_WIN64) +#include +#define __read__ _read +#define __lseek__ _lseek +#else +#include +#define __read__ read +#define __lseek__ lseek +#endif // _WIN32 || _WIN64 #include "core/inc/runtime.h" #include "core/inc/agent.h" @@ -52,12 +65,14 @@ #include "core/inc/memory_region.h" #include "core/inc/queue.h" #include "core/inc/signal.h" +#include "core/inc/cache.h" #include "core/inc/default_signal.h" #include "core/inc/interrupt_signal.h" #include "core/inc/amd_loader_context.hpp" #include "inc/hsa_ven_amd_loader.h" +#include "core/inc/hsa_ext_amd_impl.h" -using namespace amd::hsa::code; +using namespace amd::hsa; template struct ValidityError; @@ -66,6 +81,10 @@ struct ValidityError { enum { kValue = HSA_STATUS_ERROR_INVALID_SIGNAL }; }; template <> +struct ValidityError { + enum { kValue = HSA_STATUS_ERROR_INVALID_SIGNAL_GROUP }; +}; +template <> struct ValidityError { enum { kValue = HSA_STATUS_ERROR_INVALID_AGENT }; }; @@ -78,6 +97,10 @@ struct ValidityError { enum { kValue = HSA_STATUS_ERROR_INVALID_QUEUE }; }; template <> +struct ValidityError { + enum { kValue = HSA_STATUS_ERROR_INVALID_CACHE }; +}; +template <> struct ValidityError { enum { kValue = HSA_STATUS_ERROR_INVALID_ISA }; }; @@ -86,30 +109,60 @@ struct ValidityError { enum { kValue = ValidityError::kValue }; }; -#define IS_BAD_PTR(ptr) \ - do { \ - if ((ptr) == NULL) return HSA_STATUS_ERROR_INVALID_ARGUMENT; \ +#define IS_BAD_PTR(ptr) \ + do { \ + if ((ptr) == NULL) return HSA_STATUS_ERROR_INVALID_ARGUMENT; \ } while (false) -#define IS_BAD_PROFILE(profile) \ - do { \ - if (profile != HSA_PROFILE_BASE && \ - profile != HSA_PROFILE_FULL) { \ - return HSA_STATUS_ERROR_INVALID_ARGUMENT; \ - } \ +#define IS_BAD_PROFILE(profile) \ + do { \ + if (profile != HSA_PROFILE_BASE && \ + profile != HSA_PROFILE_FULL) { \ + return HSA_STATUS_ERROR_INVALID_ARGUMENT; \ + } \ } while (false) -#define IS_VALID(ptr) \ - do { \ - if (((ptr) == NULL) || !((ptr)->IsValid())) \ - return hsa_status_t(ValidityError::kValue); \ +#define IS_BAD_EXECUTABLE_STATE(executable_state) \ + do { \ + if (executable_state != HSA_EXECUTABLE_STATE_FROZEN && \ + executable_state != HSA_EXECUTABLE_STATE_UNFROZEN) { \ + return HSA_STATUS_ERROR_INVALID_ARGUMENT; \ + } \ } while (false) -#define CHECK_ALLOC(ptr) \ - do { \ - if ((ptr) == NULL) return HSA_STATUS_ERROR_OUT_OF_RESOURCES; \ +#define IS_BAD_ROUNDING_MODE(rounding_mode) \ + do { \ + if (rounding_mode != HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT && \ + rounding_mode != HSA_DEFAULT_FLOAT_ROUNDING_MODE_ZERO && \ + rounding_mode != HSA_DEFAULT_FLOAT_ROUNDING_MODE_NEAR) { \ + return HSA_STATUS_ERROR_INVALID_ARGUMENT; \ + } \ } while (false) -#define IS_OPEN() \ - do { \ - if (!core::Runtime::runtime_singleton_->IsOpen()) \ - return HSA_STATUS_ERROR_NOT_INITIALIZED; \ +#define IS_BAD_FP_TYPE(fp_type) \ + do { \ + if (fp_type != HSA_FP_TYPE_16 && \ + fp_type != HSA_FP_TYPE_32 && \ + fp_type != HSA_FP_TYPE_64) { \ + return HSA_STATUS_ERROR_INVALID_ARGUMENT; \ + } \ + } while (false) +#define IS_BAD_FLUSH_MODE(flush_mode) \ + do { \ + if (flush_mode != HSA_FLUSH_MODE_FTZ && \ + flush_mode != HSA_FLUSH_MODE_NON_FTZ) { \ + return HSA_STATUS_ERROR_INVALID_ARGUMENT; \ + } \ + } while (false) +#define IS_VALID(ptr) \ + do { \ + if (((ptr) == NULL) || !((ptr)->IsValid())) \ + return hsa_status_t(ValidityError::kValue); \ + } while (false) +#define CHECK_ALLOC(ptr) \ + do { \ + if ((ptr) == NULL) return HSA_STATUS_ERROR_OUT_OF_RESOURCES; \ + } while (false) +#define IS_OPEN() \ + do { \ + if (!core::Runtime::runtime_singleton_->IsOpen()) \ + return HSA_STATUS_ERROR_NOT_INITIALIZED; \ } while (false) template @@ -163,17 +216,51 @@ hsa_status_t return core::Runtime::runtime_singleton_->GetSystemInfo(attribute, value); } +hsa_status_t hsa_extension_get_name(uint16_t extension, const char** name) +{ + IS_OPEN(); + IS_BAD_PTR(name); + switch(extension) + { + case HSA_EXTENSION_FINALIZER: + *name = "HSA_EXTENSION_FINALIZER"; + break; + case HSA_EXTENSION_IMAGES: + *name = "HSA_EXTENSION_IMAGES"; + break; + case HSA_EXTENSION_PERFORMANCE_COUNTERS: + *name = "HSA_EXTENSION_PERFORMANCE_COUNTERS"; + break; + case HSA_EXTENSION_PROFILING_EVENTS: + *name = "HSA_EXTENSION_PROFILING_EVENTS"; + break; + case HSA_EXTENSION_AMD_PROFILER: + *name = "HSA_EXTENSION_AMD_PROFILER"; + break; + case HSA_EXTENSION_AMD_LOADER: + *name = "HSA_EXTENSION_AMD_LOADER"; + break; + default: + *name = "HSA_EXTENSION_INVALID"; + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + return HSA_STATUS_SUCCESS; +} + hsa_status_t hsa_system_extension_supported(uint16_t extension, uint16_t version_major, uint16_t version_minor, bool* result) { IS_OPEN(); - if (extension >= HSA_EXTENSION_COUNT || result == NULL) { + if ((extension > HSA_EXTENSION_STD_LAST && (extension < HSA_AMD_FIRST_EXTENSION || extension > HSA_AMD_LAST_EXTENSION)) || result == NULL) { return HSA_STATUS_ERROR_INVALID_ARGUMENT; } *result = false; + if(extension==HSA_EXTENSION_PERFORMANCE_COUNTERS || extension == HSA_EXTENSION_PROFILING_EVENTS) + return HSA_STATUS_SUCCESS; + uint16_t system_version_major = 0; hsa_status_t status = core::Runtime::runtime_singleton_->GetSystemInfo( HSA_SYSTEM_INFO_VERSION_MAJOR, &system_version_major); @@ -181,10 +268,6 @@ hsa_status_t if (version_major <= system_version_major) { uint16_t system_version_minor = 0; - status = core::Runtime::runtime_singleton_->GetSystemInfo( - HSA_SYSTEM_INFO_VERSION_MINOR, &system_version_minor); - assert(status == HSA_STATUS_SUCCESS); - if (version_minor <= system_version_minor) { *result = true; } @@ -193,66 +276,152 @@ hsa_status_t return HSA_STATUS_SUCCESS; } +hsa_status_t + hsa_system_major_extension_supported(uint16_t extension, uint16_t version_major, + uint16_t *version_minor, bool* result) { + IS_OPEN(); + IS_BAD_PTR(version_minor); + IS_BAD_PTR(result); + + if ((extension == HSA_EXTENSION_IMAGES) && (version_major==1)) { + *version_minor=0; + *result=true; + return HSA_STATUS_SUCCESS; + } + + if ((extension == HSA_EXTENSION_FINALIZER) && (version_major==1)) { + *version_minor=0; + *result=true; + return HSA_STATUS_SUCCESS; + } + + if ((extension == HSA_EXTENSION_AMD_LOADER) && (version_major==1)) { + *version_minor=0; + *result=true; + return HSA_STATUS_SUCCESS; + } + + *result=false; + return HSA_STATUS_SUCCESS; +} + +static size_t get_extension_table_length(uint16_t extension, uint16_t major, uint16_t minor) +{ + //Table to convert from major/minor to major/length + struct sizes_t + { + std::string name; + size_t size; + }; + static sizes_t sizes[] = { + "hsa_ext_images_1_00_pfn_t", sizeof(hsa_ext_images_1_00_pfn_t), + "hsa_ext_finalizer_1_00_pfn_t", sizeof(hsa_ext_finalizer_1_00_pfn_t), + "hsa_ven_amd_loader_1_00_pfn_t", sizeof(hsa_ven_amd_loader_1_00_pfn_t) + }; + static const size_t num_tables = sizeof(sizes)/sizeof(sizes_t); + + if(minor>99) + return 0; + + std::string name; + + switch(extension) + { + case HSA_EXTENSION_FINALIZER: + name = "hsa_ext_finalizer_"; + break; + case HSA_EXTENSION_IMAGES: + name="hsa_ext_images_"; + break; + //case HSA_EXTENSION_PERFORMANCE_COUNTERS: + // name = "hsa_ext_perf_counter_"; + // break; + //case HSA_EXTENSION_PROFILING_EVENTS: + // name = "hsa_ext_profiling_event_"; + // break; + //case HSA_EXTENSION_AMD_PROFILER: + // name = "hsa_ven_amd_profiler_"; + // break; + case HSA_EXTENSION_AMD_LOADER: + name = "hsa_ven_amd_loader_"; + break; + default: + return 0; + } + + char buff[3]; + sprintf(buff, "%02u", minor); + name+=std::to_string(major)+"_"+buff+"_pfn_t"; + + for(size_t i=0; i(table); - ext_table->hsa_ext_image_clear = hsa_ext_image_clear; - ext_table->hsa_ext_image_copy = hsa_ext_image_copy; - ext_table->hsa_ext_image_create = hsa_ext_image_create; - ext_table->hsa_ext_image_data_get_info = hsa_ext_image_data_get_info; - ext_table->hsa_ext_image_destroy = hsa_ext_image_destroy; - ext_table->hsa_ext_image_export = hsa_ext_image_export; - ext_table->hsa_ext_image_get_capability = hsa_ext_image_get_capability; - ext_table->hsa_ext_image_import = hsa_ext_image_import; - ext_table->hsa_ext_sampler_create = hsa_ext_sampler_create; - ext_table->hsa_ext_sampler_destroy = hsa_ext_sampler_destroy; + if(version_major>1) + return HSA_STATUS_ERROR; + hsa_ext_images_1_00_pfn_t ext_table; + ext_table.hsa_ext_image_clear = hsa_ext_image_clear; + ext_table.hsa_ext_image_copy = hsa_ext_image_copy; + ext_table.hsa_ext_image_create = hsa_ext_image_create; + ext_table.hsa_ext_image_data_get_info = hsa_ext_image_data_get_info; + ext_table.hsa_ext_image_destroy = hsa_ext_image_destroy; + ext_table.hsa_ext_image_export = hsa_ext_image_export; + ext_table.hsa_ext_image_get_capability = hsa_ext_image_get_capability; + ext_table.hsa_ext_image_import = hsa_ext_image_import; + ext_table.hsa_ext_sampler_create = hsa_ext_sampler_create; + ext_table.hsa_ext_sampler_destroy = hsa_ext_sampler_destroy; + memcpy(table, &ext_table, Min(sizeof(ext_table), table_length)); + return HSA_STATUS_SUCCESS; } if (extension == HSA_EXTENSION_FINALIZER) { - // Currently there is only version 1.00. - hsa_ext_finalizer_1_00_pfn_s* ext_table = - reinterpret_cast(table); - ext_table->hsa_ext_program_add_module = hsa_ext_program_add_module; - ext_table->hsa_ext_program_create = hsa_ext_program_create; - ext_table->hsa_ext_program_destroy = hsa_ext_program_destroy; - ext_table->hsa_ext_program_finalize = hsa_ext_program_finalize; - ext_table->hsa_ext_program_get_info = hsa_ext_program_get_info; - ext_table->hsa_ext_program_iterate_modules = - hsa_ext_program_iterate_modules; + if(version_major>1) + return HSA_STATUS_ERROR; + hsa_ext_finalizer_1_00_pfn_t ext_table; + ext_table.hsa_ext_program_add_module = hsa_ext_program_add_module; + ext_table.hsa_ext_program_create = hsa_ext_program_create; + ext_table.hsa_ext_program_destroy = hsa_ext_program_destroy; + ext_table.hsa_ext_program_finalize = hsa_ext_program_finalize; + ext_table.hsa_ext_program_get_info = hsa_ext_program_get_info; + ext_table.hsa_ext_program_iterate_modules = hsa_ext_program_iterate_modules; + + memcpy(table, &ext_table, Min(sizeof(ext_table), table_length)); return HSA_STATUS_SUCCESS; } if (extension == HSA_EXTENSION_AMD_LOADER) { - // Currently there is only version 1.00. - hsa_ven_amd_loader_1_00_pfn_t* ext_table = - reinterpret_cast(table); - ext_table->hsa_ven_amd_loader_query_host_address = + if(version_major>1) + return HSA_STATUS_ERROR; + hsa_ven_amd_loader_1_00_pfn_t ext_table; + ext_table.hsa_ven_amd_loader_query_host_address = hsa_ven_amd_loader_query_host_address; - ext_table->hsa_ven_amd_loader_query_segment_descriptors = + ext_table.hsa_ven_amd_loader_query_segment_descriptors = hsa_ven_amd_loader_query_segment_descriptors; + memcpy(table, &ext_table, Min(sizeof(ext_table), table_length)); + return HSA_STATUS_SUCCESS; } @@ -289,18 +458,35 @@ hsa_status_t hsa_agent_get_exception_policies(hsa_agent_t agent_handle, const core::Agent* agent = core::Agent::Convert(agent_handle); IS_VALID(agent); - // TODO: Fix me when exception policies are supported. *mask = 0; return HSA_STATUS_SUCCESS; } +hsa_status_t hsa_cache_get_info(hsa_cache_t cache, hsa_cache_info_t attribute, void *value) +{ + IS_OPEN(); + core::Cache* Cache = core::Cache::Convert(cache); + IS_VALID(Cache); + IS_BAD_PTR(value); + return Cache->GetInfo(attribute, value); +} + +hsa_status_t hsa_agent_iterate_caches(hsa_agent_t agent_handle, hsa_status_t (*callback )(hsa_cache_t cache, void *data), void *data) +{ + IS_OPEN(); + const core::Agent* agent=core::Agent::Convert(agent_handle); + IS_VALID(agent); + IS_BAD_PTR(callback); + return agent->IterateCache(callback, data); +} + hsa_status_t hsa_agent_extension_supported(uint16_t extension, hsa_agent_t agent_handle, uint16_t version_major, uint16_t version_minor, bool* result) { IS_OPEN(); - if ((result == NULL) || (extension > HSA_EXTENSION_AMD_PROFILER)) { + if ((extension > HSA_EXTENSION_STD_LAST && (extension < HSA_AMD_FIRST_EXTENSION || extension > HSA_AMD_LAST_EXTENSION)) || result == NULL) { return HSA_STATUS_ERROR_INVALID_ARGUMENT; } @@ -317,10 +503,6 @@ hsa_status_t if (version_major <= agent_version_major) { uint16_t agent_version_minor = 0; - status = - agent->GetInfo(HSA_AGENT_INFO_VERSION_MINOR, &agent_version_minor); - assert(status == HSA_STATUS_SUCCESS); - if (version_minor <= agent_version_minor) { *result = true; } @@ -330,6 +512,34 @@ hsa_status_t return HSA_STATUS_SUCCESS; } +hsa_status_t hsa_agent_major_extension_supported(uint16_t extension, hsa_agent_t agent_handle, uint16_t version_major, uint16_t *version_minor, bool *result) +{ + IS_OPEN(); + + if ((extension > HSA_EXTENSION_STD_LAST && (extension < HSA_AMD_FIRST_EXTENSION || extension > HSA_AMD_LAST_EXTENSION)) || result == NULL) { + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + + *result = false; + + const core::Agent* agent = core::Agent::Convert(agent_handle); + IS_VALID(agent); + + if (agent->device_type() == core::Agent::kAmdGpuDevice) { + uint16_t agent_version_major = 0; + hsa_status_t status = + agent->GetInfo(HSA_AGENT_INFO_VERSION_MAJOR, &agent_version_major); + assert(status == HSA_STATUS_SUCCESS); + + if (version_major <= agent_version_major) { + *version_minor = 0; + *result = true; + } + } + + return HSA_STATUS_SUCCESS; +} + /// @brief Api to create a user mode queue. /// /// @param agent Hsa Agent which will execute Aql commands @@ -453,7 +663,7 @@ hsa_status_t hsa_queue_inactivate(hsa_queue_t* queue) { /// @param queue Pointer to the queue whose read index is being read /// /// @return uint64_t Value of Read index -uint64_t hsa_queue_load_read_index_acquire(const hsa_queue_t* queue) { +uint64_t hsa_queue_load_read_index_scacquire(const hsa_queue_t* queue) { core::Queue* cmd_queue = core::Queue::Convert(queue); assert(IsValid(cmd_queue)); return cmd_queue->LoadReadIndexAcquire(); @@ -475,7 +685,7 @@ uint64_t hsa_queue_load_read_index_relaxed(const hsa_queue_t* queue) { /// @param queue Pointer to the queue whose write index is being read /// /// @return uint64_t Value of Write index -uint64_t hsa_queue_load_write_index_acquire(const hsa_queue_t* queue) { +uint64_t hsa_queue_load_write_index_scacquire(const hsa_queue_t* queue) { core::Queue* cmd_queue = core::Queue::Convert(queue); assert(IsValid(cmd_queue)); return cmd_queue->LoadWriteIndexAcquire(); @@ -509,7 +719,7 @@ void hsa_queue_store_read_index_relaxed(const hsa_queue_t* queue, /// @param queue Pointer to the queue whose read index is being updated /// /// @param value Value of new read index -void hsa_queue_store_read_index_release(const hsa_queue_t* queue, +void hsa_queue_store_read_index_screlease(const hsa_queue_t* queue, uint64_t value) { core::Queue* cmd_queue = core::Queue::Convert(queue); assert(IsValid(cmd_queue)); @@ -533,7 +743,7 @@ void hsa_queue_store_write_index_relaxed(const hsa_queue_t* queue, /// @param queue Pointer to the queue whose write index is being updated /// /// @param value Value of new write index -void hsa_queue_store_write_index_release(const hsa_queue_t* queue, +void hsa_queue_store_write_index_screlease(const hsa_queue_t* queue, uint64_t value) { core::Queue* cmd_queue = core::Queue::Convert(queue); assert(IsValid(cmd_queue)); @@ -550,7 +760,7 @@ void hsa_queue_store_write_index_release(const hsa_queue_t* queue, /// @param value Value of new write index /// /// @return uint64_t Value of write index before the update -uint64_t hsa_queue_cas_write_index_acq_rel(const hsa_queue_t* queue, +uint64_t hsa_queue_cas_write_index_scacq_screl(const hsa_queue_t* queue, uint64_t expected, uint64_t value) { core::Queue* cmd_queue = core::Queue::Convert(queue); @@ -568,7 +778,7 @@ uint64_t hsa_queue_cas_write_index_acq_rel(const hsa_queue_t* queue, /// @param value Value of new write index /// /// @return uint64_t Value of write index before the update -uint64_t hsa_queue_cas_write_index_acquire(const hsa_queue_t* queue, +uint64_t hsa_queue_cas_write_index_scacquire(const hsa_queue_t* queue, uint64_t expected, uint64_t value) { core::Queue* cmd_queue = core::Queue::Convert(queue); @@ -604,7 +814,7 @@ uint64_t hsa_queue_cas_write_index_relaxed(const hsa_queue_t* queue, /// @param value Value of new write index /// /// @return uint64_t Value of write index before the update -uint64_t hsa_queue_cas_write_index_release(const hsa_queue_t* queue, +uint64_t hsa_queue_cas_write_index_screlease(const hsa_queue_t* queue, uint64_t expected, uint64_t value) { core::Queue* cmd_queue = core::Queue::Convert(queue); @@ -620,7 +830,7 @@ uint64_t hsa_queue_cas_write_index_release(const hsa_queue_t* queue, /// @param value Value to add to write index /// /// @return uint64_t Value of write index before the update -uint64_t hsa_queue_add_write_index_acq_rel(const hsa_queue_t* queue, +uint64_t hsa_queue_add_write_index_scacq_screl(const hsa_queue_t* queue, uint64_t value) { core::Queue* cmd_queue = core::Queue::Convert(queue); assert(IsValid(cmd_queue)); @@ -634,7 +844,7 @@ uint64_t hsa_queue_add_write_index_acq_rel(const hsa_queue_t* queue, /// @param value Value to add to write index /// /// @return uint64_t Value of write index before the update -uint64_t hsa_queue_add_write_index_acquire(const hsa_queue_t* queue, +uint64_t hsa_queue_add_write_index_scacquire(const hsa_queue_t* queue, uint64_t value) { core::Queue* cmd_queue = core::Queue::Convert(queue); assert(IsValid(cmd_queue)); @@ -662,7 +872,7 @@ uint64_t hsa_queue_add_write_index_relaxed(const hsa_queue_t* queue, /// @param value Value to add to write index /// /// @return uint64_t Value of write index before the update -uint64_t hsa_queue_add_write_index_release(const hsa_queue_t* queue, +uint64_t hsa_queue_add_write_index_screlease(const hsa_queue_t* queue, uint64_t value) { core::Queue* cmd_queue = core::Queue::Convert(queue); assert(IsValid(cmd_queue)); @@ -841,7 +1051,7 @@ hsa_signal_value_t hsa_signal_load_relaxed(hsa_signal_t hsa_signal) { return signal->LoadRelaxed(); } -hsa_signal_value_t hsa_signal_load_acquire(hsa_signal_t hsa_signal) { +hsa_signal_value_t hsa_signal_load_scacquire(hsa_signal_t hsa_signal) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); return signal->LoadAcquire(); @@ -854,7 +1064,7 @@ void hsa_signal_store_relaxed(hsa_signal_t hsa_signal, signal->StoreRelaxed(value); } -void hsa_signal_store_release(hsa_signal_t hsa_signal, +void hsa_signal_store_screlease(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); @@ -874,7 +1084,7 @@ hsa_signal_value_t } hsa_signal_value_t - hsa_signal_wait_acquire(hsa_signal_t hsa_signal, + hsa_signal_wait_scacquire(hsa_signal_t hsa_signal, hsa_signal_condition_t condition, hsa_signal_value_t compare_value, uint64_t timeout_hint, @@ -885,6 +1095,54 @@ hsa_signal_value_t wait_state_hint); } +hsa_status_t hsa_signal_group_create(uint32_t num_signals, const hsa_signal_t *signals, uint32_t num_consumers, const hsa_agent_t *consumers, hsa_signal_group_t *signal_group) +{ + IS_OPEN(); + if(num_signals==0) + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + for (uint i = 0; i < num_signals; i++) + IS_VALID(core::Signal::Convert(signals[i])); + for (uint i = 0; i < num_consumers; i++) + IS_VALID(core::Agent::Convert(consumers[i])); + core::SignalGroup* group=new core::SignalGroup(num_signals, signals); + CHECK_ALLOC(group); + if(!group->IsValid()) + { + delete group; + return HSA_STATUS_ERROR_OUT_OF_RESOURCES; + } + *signal_group=core::SignalGroup::Convert(group); + return HSA_STATUS_SUCCESS; +} + +hsa_status_t hsa_signal_group_destroy(hsa_signal_group_t signal_group) +{ + IS_OPEN(); + core::SignalGroup* group = core::SignalGroup::Convert(signal_group); + IS_VALID(group); + delete group; + return HSA_STATUS_SUCCESS; +} + +hsa_status_t hsa_signal_group_wait_any_relaxed(hsa_signal_group_t signal_group, const hsa_signal_condition_t *conditions, const hsa_signal_value_t *compare_values, hsa_wait_state_t wait_state_hint, hsa_signal_t *signal, hsa_signal_value_t *value) +{ + IS_OPEN(); + const core::SignalGroup* group = core::SignalGroup::Convert(signal_group); + IS_VALID(group); + const uint32_t index = AMD::hsa_amd_signal_wait_any(group->Count(), const_cast(group->List()), const_cast(conditions), const_cast(compare_values), uint64_t(-1), wait_state_hint, value); + if(index>=group->Count()) + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + *signal=group->List()[index]; + return HSA_STATUS_SUCCESS; +} + +hsa_status_t hsa_signal_group_wait_any_scacquire(hsa_signal_group_t signal_group, const hsa_signal_condition_t *conditions, const hsa_signal_value_t *compare_values, hsa_wait_state_t wait_state_hint, hsa_signal_t *signal, hsa_signal_value_t *value) +{ + hsa_status_t ret=HSA::hsa_signal_group_wait_any_relaxed(signal_group, conditions, compare_values, wait_state_hint, signal, value); + std::atomic_thread_fence(std::memory_order_acquire); + return ret; +} + void hsa_signal_and_relaxed(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); @@ -893,21 +1151,21 @@ void } void - hsa_signal_and_acquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_and_scacquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->AndAcquire(value); } void - hsa_signal_and_release(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_and_screlease(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->AndRelease(value); } void - hsa_signal_and_acq_rel(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_and_scacq_screl(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->AndAcqRel(value); @@ -921,21 +1179,21 @@ void } void - hsa_signal_or_acquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_or_scacquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->OrAcquire(value); } void - hsa_signal_or_release(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_or_screlease(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->OrRelease(value); } void - hsa_signal_or_acq_rel(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_or_scacq_screl(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->OrAcqRel(value); @@ -949,21 +1207,21 @@ void } void - hsa_signal_xor_acquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_xor_scacquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->XorAcquire(value); } void - hsa_signal_xor_release(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_xor_screlease(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->XorRelease(value); } void - hsa_signal_xor_acq_rel(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_xor_scacq_screl(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->XorAcqRel(value); @@ -977,21 +1235,21 @@ void } void - hsa_signal_add_acquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_add_scacquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->AddAcquire(value); } void - hsa_signal_add_release(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_add_screlease(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->AddRelease(value); } void - hsa_signal_add_acq_rel(hsa_signal_t hsa_signal, hsa_signal_value_t value) { + hsa_signal_add_scacq_screl(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->AddAcqRel(value); @@ -1004,21 +1262,21 @@ void hsa_signal_subtract_relaxed(hsa_signal_t hsa_signal, signal->SubRelaxed(value); } -void hsa_signal_subtract_acquire(hsa_signal_t hsa_signal, +void hsa_signal_subtract_scacquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->SubAcquire(value); } -void hsa_signal_subtract_release(hsa_signal_t hsa_signal, +void hsa_signal_subtract_screlease(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); signal->SubRelease(value); } -void hsa_signal_subtract_acq_rel(hsa_signal_t hsa_signal, +void hsa_signal_subtract_scacq_screl(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); @@ -1034,7 +1292,7 @@ hsa_signal_value_t } hsa_signal_value_t - hsa_signal_exchange_acquire(hsa_signal_t hsa_signal, + hsa_signal_exchange_scacquire(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); @@ -1042,7 +1300,7 @@ hsa_signal_value_t } hsa_signal_value_t - hsa_signal_exchange_release(hsa_signal_t hsa_signal, + hsa_signal_exchange_screlease(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); @@ -1050,7 +1308,7 @@ hsa_signal_value_t } hsa_signal_value_t - hsa_signal_exchange_acq_rel(hsa_signal_t hsa_signal, + hsa_signal_exchange_scacq_screl(hsa_signal_t hsa_signal, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); assert(IsValid(signal)); @@ -1065,7 +1323,7 @@ hsa_signal_value_t hsa_signal_cas_relaxed(hsa_signal_t hsa_signal, return signal->CasRelaxed(expected, value); } -hsa_signal_value_t hsa_signal_cas_acquire(hsa_signal_t hsa_signal, +hsa_signal_value_t hsa_signal_cas_scacquire(hsa_signal_t hsa_signal, hsa_signal_value_t expected, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); @@ -1073,7 +1331,7 @@ hsa_signal_value_t hsa_signal_cas_acquire(hsa_signal_t hsa_signal, return signal->CasAcquire(expected, value); } -hsa_signal_value_t hsa_signal_cas_release(hsa_signal_t hsa_signal, +hsa_signal_value_t hsa_signal_cas_screlease(hsa_signal_t hsa_signal, hsa_signal_value_t expected, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); @@ -1081,7 +1339,7 @@ hsa_signal_value_t hsa_signal_cas_release(hsa_signal_t hsa_signal, return signal->CasRelease(expected, value); } -hsa_signal_value_t hsa_signal_cas_acq_rel(hsa_signal_t hsa_signal, +hsa_signal_value_t hsa_signal_cas_scacq_screl(hsa_signal_t hsa_signal, hsa_signal_value_t expected, hsa_signal_value_t value) { core::Signal* signal = core::Signal::Convert(hsa_signal); @@ -1089,26 +1347,52 @@ hsa_signal_value_t hsa_signal_cas_acq_rel(hsa_signal_t hsa_signal, return signal->CasAcqRel(expected, value); } -//----------------------------------------------------------------------------- -// Isa -//----------------------------------------------------------------------------- +//===--- Instruction Set Architecture -------------------------------------===// -hsa_status_t hsa_isa_from_name(const char* name, hsa_isa_t* isa) { +using core::Isa; +using core::IsaRegistry; +using core::Wavefront; + +hsa_status_t hsa_isa_from_name( + const char *name, + hsa_isa_t *isa) { IS_OPEN(); IS_BAD_PTR(name); IS_BAD_PTR(isa); - const core::Isa* isa_object = core::IsaRegistry::GetIsa(name); + const Isa *isa_object = IsaRegistry::GetIsa(name); if (!isa_object) { return HSA_STATUS_ERROR_INVALID_ISA_NAME; } - *isa = core::Isa::Handle(isa_object); + *isa = Isa::Handle(isa_object); return HSA_STATUS_SUCCESS; } -hsa_status_t hsa_isa_get_info(hsa_isa_t isa, hsa_isa_info_t attribute, - uint32_t index, void* value) { +hsa_status_t hsa_agent_iterate_isas( + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_isa_t isa, + void *data), + void *data) { + IS_OPEN(); + IS_BAD_PTR(callback); + + const core::Agent *agent_object = core::Agent::Convert(agent); + IS_VALID(agent_object); + + const Isa *isa_object = agent_object->isa(); + if (!isa_object) { + return HSA_STATUS_ERROR_INVALID_AGENT; + } + + return callback(Isa::Handle(isa_object), data); +} + +/* deprecated */ hsa_status_t hsa_isa_get_info( + hsa_isa_t isa, + hsa_isa_info_t attribute, + uint32_t index, + void *value) { IS_OPEN(); IS_BAD_PTR(value); @@ -1116,231 +1400,358 @@ hsa_status_t hsa_isa_get_info(hsa_isa_t isa, hsa_isa_info_t attribute, return HSA_STATUS_ERROR_INVALID_INDEX; } - const core::Isa* isa_object = core::Isa::Object(isa); + const Isa *isa_object = Isa::Object(isa); IS_VALID(isa_object); return isa_object->GetInfo(attribute, value) ? - HSA_STATUS_SUCCESS : HSA_STATUS_ERROR_INVALID_ARGUMENT; + HSA_STATUS_SUCCESS : HSA_STATUS_ERROR_INVALID_ARGUMENT; } -hsa_status_t hsa_isa_compatible(hsa_isa_t code_object_isa, - hsa_isa_t agent_isa, bool* result) { +hsa_status_t hsa_isa_get_info_alt( + hsa_isa_t isa, + hsa_isa_info_t attribute, + void *value) { + IS_OPEN(); + IS_BAD_PTR(value); + + const Isa *isa_object = Isa::Object(isa); + IS_VALID(isa_object); + + return isa_object->GetInfo(attribute, value) ? + HSA_STATUS_SUCCESS : HSA_STATUS_ERROR_INVALID_ARGUMENT; +} + +hsa_status_t hsa_isa_get_exception_policies( + hsa_isa_t isa, + hsa_profile_t profile, + uint16_t *mask) { + IS_OPEN(); + IS_BAD_PROFILE(profile); + IS_BAD_PTR(mask); + + const Isa *isa_object = Isa::Object(isa); + IS_VALID(isa_object); + + // FIXME: update when exception policies are supported. + *mask = 0; + return HSA_STATUS_SUCCESS; +} + +hsa_status_t hsa_isa_get_round_method( + hsa_isa_t isa, + hsa_fp_type_t fp_type, + hsa_flush_mode_t flush_mode, + hsa_round_method_t *round_method) { + IS_OPEN(); + IS_BAD_FP_TYPE(fp_type); + IS_BAD_FLUSH_MODE(flush_mode); + IS_BAD_PTR(round_method); + + const Isa *isa_object = Isa::Object(isa); + IS_VALID(isa_object); + + *round_method = isa_object->GetRoundMethod(fp_type, flush_mode); + return HSA_STATUS_SUCCESS; +} + +hsa_status_t hsa_wavefront_get_info( + hsa_wavefront_t wavefront, + hsa_wavefront_info_t attribute, + void *value) { + IS_OPEN(); + IS_BAD_PTR(value); + + const Wavefront *wavefront_object = Wavefront::Object(wavefront); + if (!wavefront_object) { + return HSA_STATUS_ERROR_INVALID_WAVEFRONT; + } + + return wavefront_object->GetInfo(attribute, value) ? + HSA_STATUS_SUCCESS : HSA_STATUS_ERROR_INVALID_ARGUMENT; +} + +hsa_status_t hsa_isa_iterate_wavefronts( + hsa_isa_t isa, + hsa_status_t (*callback)(hsa_wavefront_t wavefront, + void *data), + void *data) { + IS_OPEN(); + IS_BAD_PTR(callback); + + const Isa *isa_object = Isa::Object(isa); + IS_VALID(isa_object); + + const Wavefront *wavefront_object = isa_object->GetWavefront(); + assert(wavefront_object); + + return callback(Wavefront::Handle(wavefront_object), data); +} + +/* deprecated */ hsa_status_t hsa_isa_compatible( + hsa_isa_t code_object_isa, + hsa_isa_t agent_isa, + bool *result) { IS_OPEN(); IS_BAD_PTR(result); - const core::Isa* code_object_isa_object = core::Isa::Object(code_object_isa); + const Isa *code_object_isa_object = Isa::Object(code_object_isa); IS_VALID(code_object_isa_object); - const core::Isa* agent_isa_object = core::Isa::Object(agent_isa); + const Isa *agent_isa_object = Isa::Object(agent_isa); IS_VALID(agent_isa_object); *result = code_object_isa_object->IsCompatible(agent_isa_object); return HSA_STATUS_SUCCESS; } -//----------------------------------------------------------------------------- -// Code object. -//----------------------------------------------------------------------------- +//===--- Code Objects (deprecated) ----------------------------------------===// + +using code::AmdHsaCode; +using code::AmdHsaCodeManager; namespace { -hsa_status_t IsCodeObjectAllocRegion(hsa_region_t region, void *data) -{ - assert(nullptr != data); - assert(0 == ((hsa_region_t*)data)->handle); +hsa_status_t IsCodeObjectAllocRegion( + hsa_region_t region, + void *data) { + assert(data); + assert(((hsa_region_t*)data)->handle == 0); - hsa_status_t status = HSA_STATUS_SUCCESS; - bool alloc_allowed; - if (HSA_STATUS_SUCCESS != (status = HSA::hsa_region_get_info(region, HSA_REGION_INFO_RUNTIME_ALLOC_ALLOWED, &alloc_allowed))) { + bool runtime_alloc_allowed = false; + hsa_status_t status = HSA::hsa_region_get_info( + region, HSA_REGION_INFO_RUNTIME_ALLOC_ALLOWED, &runtime_alloc_allowed); + if (status != HSA_STATUS_SUCCESS) { return status; } - if (true == alloc_allowed) { + + if (runtime_alloc_allowed) { ((hsa_region_t*)data)->handle = region.handle; return HSA_STATUS_INFO_BREAK; } + return HSA_STATUS_SUCCESS; } -hsa_status_t FindCodeObjectAllocRegionFromAgent(hsa_agent_t agent, void *data) -{ - assert(nullptr != data); - assert(0 == ((hsa_region_t*)data)->handle); +hsa_status_t FindCodeObjectAllocRegionForAgent( + hsa_agent_t agent, + void *data) { + assert(data); + assert(((hsa_region_t*)data)->handle == 0); - hsa_status_t status = HSA_STATUS_SUCCESS; - hsa_device_type_t agent_type; - if (HSA_STATUS_SUCCESS != (status = HSA::hsa_agent_get_info(agent, HSA_AGENT_INFO_DEVICE, &agent_type))) { + hsa_device_type_t device = HSA_DEVICE_TYPE_CPU; + hsa_status_t status = HSA::hsa_agent_get_info( + agent, HSA_AGENT_INFO_DEVICE, &device); + if (status != HSA_STATUS_SUCCESS) { return status; } - if (HSA_DEVICE_TYPE_CPU == agent_type) { + + if (device == HSA_DEVICE_TYPE_CPU) { return HSA::hsa_agent_iterate_regions(agent, IsCodeObjectAllocRegion, data); } + return HSA_STATUS_SUCCESS; } -hsa_status_t FindCodeObjectAllocRegionFromSystem(void *data) -{ - assert(nullptr != data); +hsa_status_t FindCodeObjectAllocRegion( + void *data) { + assert(data); + assert(((hsa_region_t*)data)->handle == 0); - ((hsa_region_t*)data)->handle = 0; - return HSA::hsa_iterate_agents(FindCodeObjectAllocRegionFromAgent, data); + return HSA::hsa_iterate_agents(FindCodeObjectAllocRegionForAgent, data); +} + +AmdHsaCodeManager *GetCodeManager() { + return core::Runtime::runtime_singleton_->code_manager(); } } // namespace anonymous -hsa_status_t hsa_code_object_serialize( +/* deprecated */ hsa_status_t hsa_code_object_serialize( hsa_code_object_t code_object, - hsa_status_t (*alloc_callback)(size_t size, hsa_callback_data_t data, - void** address), - hsa_callback_data_t callback_data, const char* options, - void** serialized_code_object, size_t* serialized_code_object_size) { + hsa_status_t (*alloc_callback)(size_t size, + hsa_callback_data_t data, + void **address), + hsa_callback_data_t callback_data, + const char *options, + void **serialized_code_object, + size_t *serialized_code_object_size) { IS_OPEN(); IS_BAD_PTR(alloc_callback); IS_BAD_PTR(serialized_code_object); IS_BAD_PTR(serialized_code_object_size); - AmdHsaCode* code = core::Runtime::runtime_singleton_->code_manager()->FromHandle(code_object); - if (!code) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } - size_t elfmemsz = code->ElfSize(); - const char* elfmemrd = code->ElfData(); - - hsa_status_t hsc = alloc_callback(elfmemsz, - callback_data, - serialized_code_object); - if (HSA_STATUS_SUCCESS != hsc) { - return hsc; + AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); + if (!code) { + return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } - memcpy(*serialized_code_object, elfmemrd, elfmemsz); - *serialized_code_object_size = elfmemsz; + hsa_status_t status = alloc_callback( + code->ElfSize(), callback_data, serialized_code_object); + if (status != HSA_STATUS_SUCCESS) { + return status; + } + assert(*serialized_code_object); + status = HSA::hsa_memory_copy( + *serialized_code_object, code->ElfData(), code->ElfSize()); + if (status != HSA_STATUS_SUCCESS) { + return status; + } + + *serialized_code_object_size = code->ElfSize(); return HSA_STATUS_SUCCESS; } -hsa_status_t - hsa_code_object_deserialize(void* serialized_code_object, - size_t serialized_code_object_size, - const char* options, - hsa_code_object_t* code_object) { +/* deprecated */ hsa_status_t hsa_code_object_deserialize( + void *serialized_code_object, + size_t serialized_code_object_size, + const char *options, + hsa_code_object_t *code_object) { IS_OPEN(); IS_BAD_PTR(serialized_code_object); IS_BAD_PTR(code_object); - if (!serialized_code_object_size) { + if (serialized_code_object_size == 0) { return HSA_STATUS_ERROR_INVALID_ARGUMENT; } - hsa_status_t status = HSA_STATUS_SUCCESS; - - // Find code object allocation region. - hsa_region_t code_object_alloc_region; - status = FindCodeObjectAllocRegionFromSystem(&code_object_alloc_region); - if (HSA_STATUS_SUCCESS != status && HSA_STATUS_INFO_BREAK != status) { + hsa_region_t code_object_alloc_region = {0}; + hsa_status_t status = FindCodeObjectAllocRegion(&code_object_alloc_region); + if (status != HSA_STATUS_SUCCESS && status != HSA_STATUS_INFO_BREAK) { return status; } - assert(0 != code_object_alloc_region.handle); + assert(code_object_alloc_region.handle != 0); - // Allocate code object memory. - void *code_object_alloc_mem = nullptr; - status = HSA::hsa_memory_allocate(code_object_alloc_region, - serialized_code_object_size, - &code_object_alloc_mem); - if (HSA_STATUS_SUCCESS != status) { + void *code_object_alloc_data = nullptr; + status = HSA::hsa_memory_allocate( + code_object_alloc_region, serialized_code_object_size, + &code_object_alloc_data); + if (status != HSA_STATUS_SUCCESS) { return status; } - assert(nullptr != code_object_alloc_mem); + assert(code_object_alloc_data); - // Copy code object into allocated code object memory. - status = HSA::hsa_memory_copy(code_object_alloc_mem, - serialized_code_object, - serialized_code_object_size); - if (HSA_STATUS_SUCCESS != status) { + status = HSA::hsa_memory_copy( + code_object_alloc_data, serialized_code_object, + serialized_code_object_size); + if (status != HSA_STATUS_SUCCESS) { return status; } - code_object->handle = (uint64_t) (uintptr_t) code_object_alloc_mem; + code_object->handle = reinterpret_cast(code_object_alloc_data); return HSA_STATUS_SUCCESS; } -hsa_status_t hsa_code_object_destroy(hsa_code_object_t code_object) { +/* deprecated */ hsa_status_t hsa_code_object_destroy( + hsa_code_object_t code_object) { IS_OPEN(); - void *elfmemrd = reinterpret_cast(code_object.handle); - if (!elfmemrd) { + void *code_object_data = reinterpret_cast(code_object.handle); + if (!code_object_data) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } - if (!core::Runtime::runtime_singleton_->code_manager()->Destroy(code_object)) { + if (!GetCodeManager()->Destroy(code_object)) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } - HSA::hsa_memory_free(elfmemrd); - + HSA::hsa_memory_free(code_object_data); return HSA_STATUS_SUCCESS; } -hsa_status_t hsa_code_object_get_info(hsa_code_object_t code_object, - hsa_code_object_info_t attribute, - void* value) { +/* deprecated */ hsa_status_t hsa_code_object_get_info( + hsa_code_object_t code_object, + hsa_code_object_info_t attribute, + void *value) { IS_OPEN(); IS_BAD_PTR(value); - AmdHsaCode* code = core::Runtime::runtime_singleton_->code_manager()->FromHandle(code_object); + AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); if (!code) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } + switch (attribute) { case HSA_CODE_OBJECT_INFO_ISA: { - // TODO: currently AmdHsaCode::GetInfo return string representation. - // Fix when compute capability is available in libamdhsacode. char isa_name[64]; hsa_status_t status = code->GetInfo(attribute, &isa_name); - if (status != HSA_STATUS_SUCCESS) { return status; } - if (HSA_STATUS_SUCCESS != HSA::hsa_isa_from_name(isa_name, (hsa_isa_t*)value)) { - return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; + if (status != HSA_STATUS_SUCCESS) { + return status; } + + hsa_isa_t isa_handle = {0}; + status = HSA::hsa_isa_from_name(isa_name, &isa_handle); + if (status != HSA_STATUS_SUCCESS) { + return status; + } + + *((hsa_isa_t*)value) = isa_handle; return HSA_STATUS_SUCCESS; } - default: + default: { return code->GetInfo(attribute, value); } + } } -hsa_status_t hsa_code_object_get_symbol(hsa_code_object_t code_object, - const char *symbol_name, - hsa_code_symbol_t *symbol) { +/* deprecated */ hsa_status_t hsa_code_object_get_symbol( + hsa_code_object_t code_object, + const char *symbol_name, + hsa_code_symbol_t *symbol) { IS_OPEN(); IS_BAD_PTR(symbol_name); IS_BAD_PTR(symbol); - AmdHsaCode* code = core::Runtime::runtime_singleton_->code_manager()->FromHandle(code_object); + AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); if (!code) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } - // TODO: module_name is NULL until spec is changed, waiting for - // Mario. - return code->GetSymbol(NULL, symbol_name, symbol); + return code->GetSymbol(nullptr, symbol_name, symbol); } -hsa_status_t hsa_code_symbol_get_info(hsa_code_symbol_t code_symbol, - hsa_code_symbol_info_t attribute, - void* value) { +/* deprecated */ hsa_status_t hsa_code_object_get_symbol_from_name( + hsa_code_object_t code_object, + const char *module_name, + const char *symbol_name, + hsa_code_symbol_t *symbol) { + IS_OPEN(); + IS_BAD_PTR(symbol_name); + IS_BAD_PTR(symbol); + + AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); + if (!code) { + return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; + } + + return code->GetSymbol(module_name, symbol_name, symbol); +} + +/* deprecated */ hsa_status_t hsa_code_symbol_get_info( + hsa_code_symbol_t code_symbol, + hsa_code_symbol_info_t attribute, + void *value) { IS_OPEN(); IS_BAD_PTR(value); - Symbol* sym = Symbol::FromHandle(code_symbol); - return sym->GetInfo(attribute, value); + code::Symbol *symbol = code::Symbol::FromHandle(code_symbol); + if (!symbol) { + return HSA_STATUS_ERROR_INVALID_CODE_SYMBOL; + } + + return symbol->GetInfo(attribute, value); } -hsa_status_t hsa_code_object_iterate_symbols( +/* deprecated */ hsa_status_t hsa_code_object_iterate_symbols( hsa_code_object_t code_object, hsa_status_t (*callback)(hsa_code_object_t code_object, - hsa_code_symbol_t symbol, void* data), - void* data) { + hsa_code_symbol_t symbol, + void *data), + void *data) { IS_OPEN(); IS_BAD_PTR(callback); - AmdHsaCode* code = core::Runtime::runtime_singleton_->code_manager()->FromHandle(code_object); + AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); if (!code) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } @@ -1348,72 +1759,259 @@ hsa_status_t hsa_code_object_iterate_symbols( return code->IterateSymbols(code_object, callback, data); } -//----------------------------------------------------------------------------- -// Executable -//----------------------------------------------------------------------------- +//===--- Executable -------------------------------------------------------===// -hsa_status_t - hsa_executable_create(hsa_profile_t profile, - hsa_executable_state_t executable_state, - const char* options, hsa_executable_t* executable) { +using common::Signed; +using loader::Executable; +using loader::Loader; + +namespace { + +/// @class CodeObjectReaderWrapper. +/// @brief Code Object Reader Wrapper. +struct CodeObjectReaderWrapper final : Signed<0x266E71EDBC718D2C> { + /// @returns Handle equivalent of @p object. + static hsa_code_object_reader_t Handle( + const CodeObjectReaderWrapper *object) { + hsa_code_object_reader_t handle = {reinterpret_cast(object)}; + return handle; + } + + /// @returns Object equivalent of @p handle. + static CodeObjectReaderWrapper *Object( + const hsa_code_object_reader_t &handle) { + CodeObjectReaderWrapper *object = common::ObjectAt( + handle.handle); + return object; + } + + /// @brief Default constructor. + CodeObjectReaderWrapper( + const void *_code_object_memory, size_t _code_object_size, + bool _comes_from_file) + : code_object_memory(_code_object_memory) + , code_object_size(_code_object_size) + , comes_from_file(_comes_from_file) {} + + /// @brief Default destructor. + ~CodeObjectReaderWrapper() {} + + const void *code_object_memory; + const size_t code_object_size; + const bool comes_from_file; +}; + +Loader *GetLoader() { + return core::Runtime::runtime_singleton_->loader(); +} + +} // namespace anonymous + +hsa_status_t hsa_code_object_reader_create_from_file( + hsa_file_t file, + hsa_code_object_reader_t *code_object_reader) { IS_OPEN(); - IS_BAD_PTR(executable); + IS_BAD_PTR(code_object_reader); - if (HSA_PROFILE_BASE != profile && HSA_PROFILE_FULL != profile) { - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - if (HSA_EXECUTABLE_STATE_FROZEN != executable_state && - HSA_EXECUTABLE_STATE_UNFROZEN != executable_state) { - return HSA_STATUS_ERROR_INVALID_ARGUMENT; + off_t file_size = __lseek__(file, 0, SEEK_END); + if (file_size == (off_t)-1) { + return HSA_STATUS_ERROR_INVALID_FILE; } - amd::hsa::loader::Executable *exec = core::Runtime::runtime_singleton_->loader()->CreateExecutable( - profile, options); - if (!exec) { + if (__lseek__(file, 0, SEEK_SET) == (off_t)-1) { + return HSA_STATUS_ERROR_INVALID_FILE; + } + + unsigned char *code_object_memory = new unsigned char[file_size]; + CHECK_ALLOC(code_object_memory); + + if (__read__(file, code_object_memory, file_size) != file_size) { + delete [] code_object_memory; + return HSA_STATUS_ERROR_INVALID_FILE; + } + + CodeObjectReaderWrapper *wrapper = new (std::nothrow) CodeObjectReaderWrapper( + code_object_memory, file_size, true); + if (!wrapper) { + delete [] code_object_memory; return HSA_STATUS_ERROR_OUT_OF_RESOURCES; } - // TODO: why did we make it possible to create frozen executable? - if (HSA_EXECUTABLE_STATE_FROZEN == executable_state) { - exec->Freeze(NULL); - } - - *executable = amd::hsa::loader::Executable::Handle(exec); + *code_object_reader = CodeObjectReaderWrapper::Handle(wrapper); return HSA_STATUS_SUCCESS; } -hsa_status_t hsa_executable_destroy(hsa_executable_t executable) { +hsa_status_t hsa_code_object_reader_create_from_memory( + const void *code_object, + size_t size, + hsa_code_object_reader_t *code_object_reader) { + IS_OPEN(); + IS_BAD_PTR(code_object); + IS_BAD_PTR(code_object_reader); + + if (size == 0) { + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + + CodeObjectReaderWrapper *wrapper = new (std::nothrow) CodeObjectReaderWrapper( + code_object, size, false); + CHECK_ALLOC(wrapper); + + *code_object_reader = CodeObjectReaderWrapper::Handle(wrapper); + return HSA_STATUS_SUCCESS; +} + +hsa_status_t hsa_code_object_reader_destroy( + hsa_code_object_reader_t code_object_reader) { IS_OPEN(); - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + CodeObjectReaderWrapper *wrapper = CodeObjectReaderWrapper::Object( + code_object_reader); + if (!wrapper) { + return HSA_STATUS_ERROR_INVALID_CODE_OBJECT_READER; + } + + if (wrapper->comes_from_file) { + delete [] (unsigned char*)wrapper->code_object_memory; + } + delete wrapper; + + return HSA_STATUS_SUCCESS; +} + +/* deprecated */ hsa_status_t hsa_executable_create( + hsa_profile_t profile, + hsa_executable_state_t executable_state, + const char *options, + hsa_executable_t *executable) { + IS_OPEN(); + IS_BAD_PROFILE(profile); + IS_BAD_EXECUTABLE_STATE(executable_state); + IS_BAD_PTR(executable); + + // Invoke non-deprecated API. + hsa_status_t status = HSA::hsa_executable_create_alt( + profile, HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT, options, executable); + if (status != HSA_STATUS_SUCCESS) { + return status; + } + + Executable *exec = Executable::Object(*executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } - core::Runtime::runtime_singleton_->loader()->DestroyExecutable(exec); + if (executable_state == HSA_EXECUTABLE_STATE_FROZEN) { + exec->Freeze(nullptr); + } + return HSA_STATUS_SUCCESS; } -hsa_status_t - hsa_executable_load_code_object(hsa_executable_t executable, - hsa_agent_t agent, - hsa_code_object_t code_object, - const char* options) { +hsa_status_t hsa_executable_create_alt( + hsa_profile_t profile, + hsa_default_float_rounding_mode_t default_float_rounding_mode, + const char *options, + hsa_executable_t *executable) { + IS_OPEN(); + IS_BAD_PROFILE(profile); + IS_BAD_ROUNDING_MODE(default_float_rounding_mode); // NOTES: should we check + // if default float + // rounding mode is valid? + // spec does not say so. + IS_BAD_PTR(executable); + + Executable *exec = GetLoader()->CreateExecutable( + profile, options, default_float_rounding_mode); + CHECK_ALLOC(exec); + + *executable = Executable::Handle(exec); + return HSA_STATUS_SUCCESS; +} + +hsa_status_t hsa_executable_destroy( + hsa_executable_t executable) { IS_OPEN(); - amd_loaded_code_object_t loaded_code_object = {0}; - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + Executable *exec = Executable::Object(executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } - return exec->LoadCodeObject(agent, code_object, options, &loaded_code_object); + + GetLoader()->DestroyExecutable(exec); + return HSA_STATUS_SUCCESS; } -hsa_status_t - hsa_executable_freeze(hsa_executable_t executable, const char* options) { +/* deprecated */ hsa_status_t hsa_executable_load_code_object( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_code_object_t code_object, + const char *options) { IS_OPEN(); - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + Executable *exec = Executable::Object(executable); + if (!exec) { + return HSA_STATUS_ERROR_INVALID_EXECUTABLE; + } + + return exec->LoadCodeObject(agent, code_object, options); +} + +hsa_status_t hsa_executable_load_program_code_object( + hsa_executable_t executable, + hsa_code_object_reader_t code_object_reader, + const char *options, + hsa_loaded_code_object_t *loaded_code_object) { + IS_OPEN(); + + Executable *exec = Executable::Object(executable); + if (!exec) { + return HSA_STATUS_ERROR_INVALID_EXECUTABLE; + } + + CodeObjectReaderWrapper *wrapper = CodeObjectReaderWrapper::Object( + code_object_reader); + if (!wrapper) { + return HSA_STATUS_ERROR_INVALID_CODE_OBJECT_READER; + } + + hsa_code_object_t code_object = + {reinterpret_cast(wrapper->code_object_memory)}; + return exec->LoadCodeObject( + {0}, code_object, options, loaded_code_object, false); +} + +hsa_status_t hsa_executable_load_agent_code_object( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_code_object_reader_t code_object_reader, + const char *options, + hsa_loaded_code_object_t *loaded_code_object) { + IS_OPEN(); + + Executable *exec = Executable::Object(executable); + if (!exec) { + return HSA_STATUS_ERROR_INVALID_EXECUTABLE; + } + + CodeObjectReaderWrapper *wrapper = CodeObjectReaderWrapper::Object( + code_object_reader); + if (!wrapper) { + return HSA_STATUS_ERROR_INVALID_CODE_OBJECT_READER; + } + + hsa_code_object_t code_object = + {reinterpret_cast(wrapper->code_object_memory)}; + return exec->LoadCodeObject( + agent, code_object, options, loaded_code_object, false); +} + +hsa_status_t hsa_executable_freeze( + hsa_executable_t executable, + const char *options) { + IS_OPEN(); + + Executable *exec = Executable::Object(executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } @@ -1421,13 +2019,14 @@ hsa_status_t return exec->Freeze(options); } -hsa_status_t hsa_executable_get_info(hsa_executable_t executable, - hsa_executable_info_t attribute, - void* value) { +hsa_status_t hsa_executable_get_info( + hsa_executable_t executable, + hsa_executable_info_t attribute, + void *value) { IS_OPEN(); IS_BAD_PTR(value); - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + Executable *exec = Executable::Object(executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } @@ -1435,15 +2034,14 @@ hsa_status_t hsa_executable_get_info(hsa_executable_t executable, return exec->GetInfo(attribute, value); } -hsa_status_t - hsa_executable_global_variable_define(hsa_executable_t executable, - const char* variable_name, - void* address) { +hsa_status_t hsa_executable_global_variable_define( + hsa_executable_t executable, + const char *variable_name, + void *address) { IS_OPEN(); IS_BAD_PTR(variable_name); - IS_BAD_PTR(address); - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + Executable *exec = Executable::Object(executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } @@ -1451,48 +2049,47 @@ hsa_status_t return exec->DefineProgramExternalVariable(variable_name, address); } -hsa_status_t - hsa_executable_agent_global_variable_define(hsa_executable_t executable, - hsa_agent_t agent, - const char* variable_name, - void* address) { +hsa_status_t hsa_executable_agent_global_variable_define( + hsa_executable_t executable, + hsa_agent_t agent, + const char *variable_name, + void *address) { IS_OPEN(); IS_BAD_PTR(variable_name); - IS_BAD_PTR(address); - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + Executable *exec = Executable::Object(executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } return exec->DefineAgentExternalVariable( - variable_name, agent, HSA_VARIABLE_SEGMENT_GLOBAL, address); + variable_name, agent, HSA_VARIABLE_SEGMENT_GLOBAL, address); } -hsa_status_t - hsa_executable_readonly_variable_define(hsa_executable_t executable, - hsa_agent_t agent, - const char* variable_name, - void* address) { +hsa_status_t hsa_executable_readonly_variable_define( + hsa_executable_t executable, + hsa_agent_t agent, + const char *variable_name, + void *address) { IS_OPEN(); IS_BAD_PTR(variable_name); - IS_BAD_PTR(address); - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + Executable *exec = Executable::Object(executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } return exec->DefineAgentExternalVariable( - variable_name, agent, HSA_VARIABLE_SEGMENT_READONLY, address); + variable_name, agent, HSA_VARIABLE_SEGMENT_READONLY, address); } -hsa_status_t - hsa_executable_validate(hsa_executable_t executable, uint32_t* result) { +hsa_status_t hsa_executable_validate( + hsa_executable_t executable, + uint32_t *result) { IS_OPEN(); IS_BAD_PTR(result); - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + Executable *exec = Executable::Object(executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } @@ -1500,53 +2097,98 @@ hsa_status_t return exec->Validate(result); } -hsa_status_t - hsa_executable_get_symbol(hsa_executable_t executable, - const char* module_name, const char* symbol_name, - hsa_agent_t agent, int32_t call_convention, - hsa_executable_symbol_t* symbol) { +hsa_status_t hsa_executable_validate_alt( + hsa_executable_t executable, + const char *options, + uint32_t *result) { + IS_OPEN(); + IS_BAD_PTR(result); + + return HSA::hsa_executable_validate(executable, result); +} + +/* deprecated */ hsa_status_t hsa_executable_get_symbol( + hsa_executable_t executable, + const char *module_name, + const char *symbol_name, + hsa_agent_t agent, + int32_t call_convention, + hsa_executable_symbol_t *symbol) { IS_OPEN(); IS_BAD_PTR(symbol_name); IS_BAD_PTR(symbol); - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + std::string mangled_name(symbol_name); + if (mangled_name.empty()) { + return HSA_STATUS_ERROR_INVALID_SYMBOL_NAME; + } + if (module_name && !std::string(module_name).empty()) { + mangled_name.insert(0, "::"); + mangled_name.insert(0, std::string(module_name)); + } + + Executable *exec = Executable::Object(executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } - amd::hsa::loader::Symbol *sym = - exec->GetSymbol(module_name == NULL ? "" : module_name, symbol_name, agent, call_convention); + // Invoke non-deprecated API. + return HSA::hsa_executable_get_symbol_by_name( + executable, mangled_name.c_str(), + exec->IsProgramSymbol(mangled_name.c_str()) ? nullptr : &agent, symbol); +} + +hsa_status_t hsa_executable_get_symbol_by_name( + hsa_executable_t executable, + const char *symbol_name, + const hsa_agent_t *agent, // NOTES: this is not consistent with the rest of + // of the specification, but seems like a better + // approach to distinguish program/agent symbols. + hsa_executable_symbol_t *symbol) { + IS_OPEN(); + IS_BAD_PTR(symbol_name); + IS_BAD_PTR(symbol); + + Executable *exec = Executable::Object(executable); + if (!exec) { + return HSA_STATUS_ERROR_INVALID_EXECUTABLE; + } + + loader::Symbol *sym = exec->GetSymbol(symbol_name, agent); if (!sym) { return HSA_STATUS_ERROR_INVALID_SYMBOL_NAME; } - *symbol = amd::hsa::loader::Symbol::Handle(sym); + + *symbol = loader::Symbol::Handle(sym); return HSA_STATUS_SUCCESS; } -hsa_status_t - hsa_executable_symbol_get_info(hsa_executable_symbol_t executable_symbol, - hsa_executable_symbol_info_t attribute, - void* value) { +hsa_status_t hsa_executable_symbol_get_info( + hsa_executable_symbol_t executable_symbol, + hsa_executable_symbol_info_t attribute, + void *value) { IS_OPEN(); IS_BAD_PTR(value); - amd::hsa::loader::Symbol *sym = amd::hsa::loader::Symbol::Object(executable_symbol); + loader::Symbol *sym = loader::Symbol::Object(executable_symbol); if (!sym) { - return HSA_STATUS_ERROR_INVALID_ARGUMENT; + return HSA_STATUS_ERROR_INVALID_EXECUTABLE_SYMBOL; } + return sym->GetInfo(attribute, value) ? HSA_STATUS_SUCCESS : HSA_STATUS_ERROR_INVALID_ARGUMENT; } -hsa_status_t hsa_executable_iterate_symbols( +/* deprecated */ hsa_status_t hsa_executable_iterate_symbols( hsa_executable_t executable, hsa_status_t (*callback)(hsa_executable_t executable, - hsa_executable_symbol_t symbol, void* data), - void* data) { + hsa_executable_symbol_t symbol, + void *data), + void *data) { IS_OPEN(); IS_BAD_PTR(callback); - amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + Executable *exec = Executable::Object(executable); if (!exec) { return HSA_STATUS_ERROR_INVALID_EXECUTABLE; } @@ -1554,12 +2196,51 @@ hsa_status_t hsa_executable_iterate_symbols( return exec->IterateSymbols(callback, data); } -//----------------------------------------------------------------------------- -// Errors -//----------------------------------------------------------------------------- +hsa_status_t hsa_executable_iterate_agent_symbols( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_agent_t agent, + hsa_executable_symbol_t symbol, + void *data), + void *data) { + IS_OPEN(); + IS_BAD_PTR(callback); -hsa_status_t - hsa_status_string(hsa_status_t status, const char** status_string) { + // NOTES: should we check if agent is valid? spec does not say so. + const core::Agent *agent_object = core::Agent::Convert(agent); + IS_VALID(agent_object); + + Executable *exec = Executable::Object(executable); + if (!exec) { + return HSA_STATUS_ERROR_INVALID_EXECUTABLE; + } + + return exec->IterateAgentSymbols(agent, callback, data); +} + +hsa_status_t hsa_executable_iterate_program_symbols( + hsa_executable_t executable, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_executable_symbol_t symbol, + void *data), + void *data) { + IS_OPEN(); + IS_BAD_PTR(callback); + + Executable *exec = Executable::Object(executable); + if (!exec) { + return HSA_STATUS_ERROR_INVALID_EXECUTABLE; + } + + return exec->IterateProgramSymbols(callback, data); +} + +//===--- Runtime Notifications --------------------------------------------===// + +hsa_status_t hsa_status_string( + hsa_status_t status, + const char **status_string) { IS_OPEN(); IS_BAD_PTR(status_string); const size_t status_u = static_cast(status); @@ -1643,42 +2324,70 @@ hsa_status_t "a functions are not compatible."; break; case HSA_STATUS_ERROR_INVALID_INDEX: - *status_string = "The index is invalid."; + *status_string = "HSA_STATUS_ERROR_INVALID_INDEX: The index is invalid."; break; case HSA_STATUS_ERROR_INVALID_ISA: - *status_string = "The instruction set architecture is invalid."; + *status_string = "HSA_STATUS_ERROR_INVALID_ISA: The instruction set architecture is invalid."; break; case HSA_STATUS_ERROR_INVALID_CODE_OBJECT: - *status_string = "The code object is invalid."; + *status_string = "HSA_STATUS_ERROR_INVALID_CODE_OBJECT: The code object is invalid."; break; case HSA_STATUS_ERROR_INVALID_EXECUTABLE: - *status_string = "The executable is invalid."; + *status_string = "HSA_STATUS_ERROR_INVALID_EXECUTABLE: The executable is invalid."; break; case HSA_STATUS_ERROR_FROZEN_EXECUTABLE: - *status_string = "The executable is frozen."; + *status_string = "HSA_STATUS_ERROR_FROZEN_EXECUTABLE: The executable is frozen."; break; case HSA_STATUS_ERROR_INVALID_SYMBOL_NAME: - *status_string = "There is no symbol with the given name."; + *status_string = "HSA_STATUS_ERROR_INVALID_SYMBOL_NAME: There is no symbol with the given name."; break; case HSA_STATUS_ERROR_VARIABLE_ALREADY_DEFINED: - *status_string = "The variable is already defined."; + *status_string = "HSA_STATUS_ERROR_VARIABLE_ALREADY_DEFINED: The variable is already defined."; break; case HSA_STATUS_ERROR_VARIABLE_UNDEFINED: - *status_string = "The variable is undefined."; + *status_string = "HSA_STATUS_ERROR_VARIABLE_UNDEFINED: The variable is undefined."; + break; + case HSA_STATUS_ERROR_INVALID_CODE_SYMBOL : + *status_string = "HSA_STATUS_ERROR_INVALID_CODE_SYMBOL: The code object symbol is invalid."; + break; + case HSA_STATUS_ERROR_INVALID_EXECUTABLE_SYMBOL : + *status_string = "HSA_STATUS_ERROR_INVALID_EXECUTABLE_SYMBOL: The executable symbol is invalid."; + break; + case HSA_STATUS_ERROR_INVALID_FILE : + *status_string = "HSA_STATUS_ERROR_INVALID_FILE: The file descriptor is invalid."; + break; + case HSA_STATUS_ERROR_INVALID_CODE_OBJECT_READER : + *status_string = "HSA_STATUS_ERROR_INVALID_CODE_OBJECT_READER: *The code object reader is invalid."; + break; + case HSA_STATUS_ERROR_INVALID_CACHE : + *status_string = "HSA_STATUS_ERROR_INVALID_CACHE: *The cache is invalid."; + break; + case HSA_STATUS_ERROR_INVALID_WAVEFRONT : + *status_string = "HSA_STATUS_ERROR_INVALID_WAVEFRONT: *The wavefront is invalid."; + break; + case HSA_STATUS_ERROR_INVALID_SIGNAL_GROUP : + *status_string = "HSA_STATUS_ERROR_INVALID_SIGNAL_GROUP: *The signal group is invalid."; + break; + case HSA_STATUS_ERROR_INVALID_RUNTIME_STATE : + *status_string = "HSA_STATUS_ERROR_INVALID_RUNTIME_STATE: *The HSA runtime is not in the configuration state."; break; case HSA_EXT_STATUS_ERROR_IMAGE_FORMAT_UNSUPPORTED: - *status_string = - "HSA_EXT_STATUS_ERROR_IMAGE_FORMAT_UNSUPPORTED: Image " - "format is not supported."; + *status_string = "HSA_EXT_STATUS_ERROR_IMAGE_FORMAT_UNSUPPORTED: Image " + "format is not supported."; break; case HSA_EXT_STATUS_ERROR_IMAGE_SIZE_UNSUPPORTED: *status_string = - "HSA_EXT_STATUS_ERROR_IMAGE_SIZE_UNSUPPORTED: Image size " - "is not supported."; + "HSA_EXT_STATUS_ERROR_IMAGE_SIZE_UNSUPPORTED: Image size " + "is not supported."; + break; + case HSA_EXT_STATUS_ERROR_IMAGE_PITCH_UNSUPPORTED: + *status_string = "Image pitch is not supported or invalid."; + break; + case HSA_EXT_STATUS_ERROR_SAMPLER_DESCRIPTOR_UNSUPPORTED: + *status_string = "Sampler descriptor is not supported or invalid."; break; case HSA_EXT_STATUS_ERROR_INVALID_PROGRAM: - *status_string = - "HSA_EXT_STATUS_ERROR_INVALID_PROGRAM: Invalid program"; + *status_string = "HSA_EXT_STATUS_ERROR_INVALID_PROGRAM: Invalid program"; break; case HSA_EXT_STATUS_ERROR_INVALID_MODULE: *status_string = "HSA_EXT_STATUS_ERROR_INVALID_MODULE: Invalid module"; diff --git a/runtime/hsa-runtime/core/runtime/hsa_api_trace.cpp b/runtime/hsa-runtime/core/runtime/hsa_api_trace.cpp index 9fe3823a5b..c64194affd 100644 --- a/runtime/hsa-runtime/core/runtime/hsa_api_trace.cpp +++ b/runtime/hsa-runtime/core/runtime/hsa_api_trace.cpp @@ -146,38 +146,38 @@ void HsaApiTable::UpdateCore() { core_api.hsa_soft_queue_create_fn = HSA::hsa_soft_queue_create; core_api.hsa_queue_destroy_fn = HSA::hsa_queue_destroy; core_api.hsa_queue_inactivate_fn = HSA::hsa_queue_inactivate; - core_api.hsa_queue_load_read_index_acquire_fn = - HSA::hsa_queue_load_read_index_acquire; + core_api.hsa_queue_load_read_index_scacquire_fn = + HSA::hsa_queue_load_read_index_scacquire; core_api.hsa_queue_load_read_index_relaxed_fn = HSA::hsa_queue_load_read_index_relaxed; - core_api.hsa_queue_load_write_index_acquire_fn = - HSA::hsa_queue_load_write_index_acquire; + core_api.hsa_queue_load_write_index_scacquire_fn = + HSA::hsa_queue_load_write_index_scacquire; core_api.hsa_queue_load_write_index_relaxed_fn = HSA::hsa_queue_load_write_index_relaxed; core_api.hsa_queue_store_write_index_relaxed_fn = HSA::hsa_queue_store_write_index_relaxed; - core_api.hsa_queue_store_write_index_release_fn = - HSA::hsa_queue_store_write_index_release; - core_api.hsa_queue_cas_write_index_acq_rel_fn = - HSA::hsa_queue_cas_write_index_acq_rel; - core_api.hsa_queue_cas_write_index_acquire_fn = - HSA::hsa_queue_cas_write_index_acquire; + core_api.hsa_queue_store_write_index_screlease_fn = + HSA::hsa_queue_store_write_index_screlease; + core_api.hsa_queue_cas_write_index_scacq_screl_fn = + HSA::hsa_queue_cas_write_index_scacq_screl; + core_api.hsa_queue_cas_write_index_scacquire_fn = + HSA::hsa_queue_cas_write_index_scacquire; core_api.hsa_queue_cas_write_index_relaxed_fn = HSA::hsa_queue_cas_write_index_relaxed; - core_api.hsa_queue_cas_write_index_release_fn = - HSA::hsa_queue_cas_write_index_release; - core_api.hsa_queue_add_write_index_acq_rel_fn = - HSA::hsa_queue_add_write_index_acq_rel; - core_api.hsa_queue_add_write_index_acquire_fn = - HSA::hsa_queue_add_write_index_acquire; + core_api.hsa_queue_cas_write_index_screlease_fn = + HSA::hsa_queue_cas_write_index_screlease; + core_api.hsa_queue_add_write_index_scacq_screl_fn = + HSA::hsa_queue_add_write_index_scacq_screl; + core_api.hsa_queue_add_write_index_scacquire_fn = + HSA::hsa_queue_add_write_index_scacquire; core_api.hsa_queue_add_write_index_relaxed_fn = HSA::hsa_queue_add_write_index_relaxed; - core_api.hsa_queue_add_write_index_release_fn = - HSA::hsa_queue_add_write_index_release; + core_api.hsa_queue_add_write_index_screlease_fn = + HSA::hsa_queue_add_write_index_screlease; core_api.hsa_queue_store_read_index_relaxed_fn = HSA::hsa_queue_store_read_index_relaxed; - core_api.hsa_queue_store_read_index_release_fn = - HSA::hsa_queue_store_read_index_release; + core_api.hsa_queue_store_read_index_screlease_fn = + HSA::hsa_queue_store_read_index_screlease; core_api.hsa_agent_iterate_regions_fn = HSA::hsa_agent_iterate_regions; core_api.hsa_region_get_info_fn = HSA::hsa_region_get_info; core_api.hsa_memory_register_fn = HSA::hsa_memory_register; @@ -189,52 +189,72 @@ void HsaApiTable::UpdateCore() { core_api.hsa_signal_create_fn = HSA::hsa_signal_create; core_api.hsa_signal_destroy_fn = HSA::hsa_signal_destroy; core_api.hsa_signal_load_relaxed_fn = HSA::hsa_signal_load_relaxed; - core_api.hsa_signal_load_acquire_fn = HSA::hsa_signal_load_acquire; + core_api.hsa_signal_load_scacquire_fn = HSA::hsa_signal_load_scacquire; core_api.hsa_signal_store_relaxed_fn = HSA::hsa_signal_store_relaxed; - core_api.hsa_signal_store_release_fn = HSA::hsa_signal_store_release; + core_api.hsa_signal_store_screlease_fn = HSA::hsa_signal_store_screlease; core_api.hsa_signal_wait_relaxed_fn = HSA::hsa_signal_wait_relaxed; - core_api.hsa_signal_wait_acquire_fn = HSA::hsa_signal_wait_acquire; + core_api.hsa_signal_wait_scacquire_fn = HSA::hsa_signal_wait_scacquire; core_api.hsa_signal_and_relaxed_fn = HSA::hsa_signal_and_relaxed; - core_api.hsa_signal_and_acquire_fn = HSA::hsa_signal_and_acquire; - core_api.hsa_signal_and_release_fn = HSA::hsa_signal_and_release; - core_api.hsa_signal_and_acq_rel_fn = HSA::hsa_signal_and_acq_rel; + core_api.hsa_signal_and_scacquire_fn = HSA::hsa_signal_and_scacquire; + core_api.hsa_signal_and_screlease_fn = HSA::hsa_signal_and_screlease; + core_api.hsa_signal_and_scacq_screl_fn = HSA::hsa_signal_and_scacq_screl; core_api.hsa_signal_or_relaxed_fn = HSA::hsa_signal_or_relaxed; - core_api.hsa_signal_or_acquire_fn = HSA::hsa_signal_or_acquire; - core_api.hsa_signal_or_release_fn = HSA::hsa_signal_or_release; - core_api.hsa_signal_or_acq_rel_fn = HSA::hsa_signal_or_acq_rel; + core_api.hsa_signal_or_scacquire_fn = HSA::hsa_signal_or_scacquire; + core_api.hsa_signal_or_screlease_fn = HSA::hsa_signal_or_screlease; + core_api.hsa_signal_or_scacq_screl_fn = HSA::hsa_signal_or_scacq_screl; core_api.hsa_signal_xor_relaxed_fn = HSA::hsa_signal_xor_relaxed; - core_api.hsa_signal_xor_acquire_fn = HSA::hsa_signal_xor_acquire; - core_api.hsa_signal_xor_release_fn = HSA::hsa_signal_xor_release; - core_api.hsa_signal_xor_acq_rel_fn = HSA::hsa_signal_xor_acq_rel; + core_api.hsa_signal_xor_scacquire_fn = HSA::hsa_signal_xor_scacquire; + core_api.hsa_signal_xor_screlease_fn = HSA::hsa_signal_xor_screlease; + core_api.hsa_signal_xor_scacq_screl_fn = HSA::hsa_signal_xor_scacq_screl; core_api.hsa_signal_exchange_relaxed_fn = HSA::hsa_signal_exchange_relaxed; - core_api.hsa_signal_exchange_acquire_fn = HSA::hsa_signal_exchange_acquire; - core_api.hsa_signal_exchange_release_fn = HSA::hsa_signal_exchange_release; - core_api.hsa_signal_exchange_acq_rel_fn = HSA::hsa_signal_exchange_acq_rel; + core_api.hsa_signal_exchange_scacquire_fn = HSA::hsa_signal_exchange_scacquire; + core_api.hsa_signal_exchange_screlease_fn = HSA::hsa_signal_exchange_screlease; + core_api.hsa_signal_exchange_scacq_screl_fn = HSA::hsa_signal_exchange_scacq_screl; core_api.hsa_signal_add_relaxed_fn = HSA::hsa_signal_add_relaxed; - core_api.hsa_signal_add_acquire_fn = HSA::hsa_signal_add_acquire; - core_api.hsa_signal_add_release_fn = HSA::hsa_signal_add_release; - core_api.hsa_signal_add_acq_rel_fn = HSA::hsa_signal_add_acq_rel; + core_api.hsa_signal_add_scacquire_fn = HSA::hsa_signal_add_scacquire; + core_api.hsa_signal_add_screlease_fn = HSA::hsa_signal_add_screlease; + core_api.hsa_signal_add_scacq_screl_fn = HSA::hsa_signal_add_scacq_screl; core_api.hsa_signal_subtract_relaxed_fn = HSA::hsa_signal_subtract_relaxed; - core_api.hsa_signal_subtract_acquire_fn = HSA::hsa_signal_subtract_acquire; - core_api.hsa_signal_subtract_release_fn = HSA::hsa_signal_subtract_release; - core_api.hsa_signal_subtract_acq_rel_fn = HSA::hsa_signal_subtract_acq_rel; + core_api.hsa_signal_subtract_scacquire_fn = HSA::hsa_signal_subtract_scacquire; + core_api.hsa_signal_subtract_screlease_fn = HSA::hsa_signal_subtract_screlease; + core_api.hsa_signal_subtract_scacq_screl_fn = HSA::hsa_signal_subtract_scacq_screl; core_api.hsa_signal_cas_relaxed_fn = HSA::hsa_signal_cas_relaxed; - core_api.hsa_signal_cas_acquire_fn = HSA::hsa_signal_cas_acquire; - core_api.hsa_signal_cas_release_fn = HSA::hsa_signal_cas_release; - core_api.hsa_signal_cas_acq_rel_fn = HSA::hsa_signal_cas_acq_rel; + core_api.hsa_signal_cas_scacquire_fn = HSA::hsa_signal_cas_scacquire; + core_api.hsa_signal_cas_screlease_fn = HSA::hsa_signal_cas_screlease; + core_api.hsa_signal_cas_scacq_screl_fn = HSA::hsa_signal_cas_scacq_screl; + + //===--- Instruction Set Architecture -----------------------------------===// + core_api.hsa_isa_from_name_fn = HSA::hsa_isa_from_name; + // Deprecated since v1.1. core_api.hsa_isa_get_info_fn = HSA::hsa_isa_get_info; + // Deprecated since v1.1. core_api.hsa_isa_compatible_fn = HSA::hsa_isa_compatible; + + //===--- Code Objects (deprecated) --------------------------------------===// + + // Deprecated since v1.1. core_api.hsa_code_object_serialize_fn = HSA::hsa_code_object_serialize; + // Deprecated since v1.1. core_api.hsa_code_object_deserialize_fn = HSA::hsa_code_object_deserialize; + // Deprecated since v1.1. core_api.hsa_code_object_destroy_fn = HSA::hsa_code_object_destroy; + // Deprecated since v1.1. core_api.hsa_code_object_get_info_fn = HSA::hsa_code_object_get_info; + // Deprecated since v1.1. core_api.hsa_code_object_get_symbol_fn = HSA::hsa_code_object_get_symbol; + // Deprecated since v1.1. core_api.hsa_code_symbol_get_info_fn = HSA::hsa_code_symbol_get_info; + // Deprecated since v1.1. core_api.hsa_code_object_iterate_symbols_fn = HSA::hsa_code_object_iterate_symbols; + + //===--- Executable -----------------------------------------------------===// + + // Deprecated since v1.1. core_api.hsa_executable_create_fn = HSA::hsa_executable_create; core_api.hsa_executable_destroy_fn = HSA::hsa_executable_destroy; + // Deprecated since v1.1. core_api.hsa_executable_load_code_object_fn = HSA::hsa_executable_load_code_object; core_api.hsa_executable_freeze_fn = HSA::hsa_executable_freeze; @@ -246,10 +266,69 @@ void HsaApiTable::UpdateCore() { core_api.hsa_executable_readonly_variable_define_fn = HSA::hsa_executable_readonly_variable_define; core_api.hsa_executable_validate_fn = HSA::hsa_executable_validate; + // Deprecated since v1.1. core_api.hsa_executable_get_symbol_fn = HSA::hsa_executable_get_symbol; - core_api.hsa_executable_symbol_get_info_fn = HSA::hsa_executable_symbol_get_info; - core_api.hsa_executable_iterate_symbols_fn = HSA::hsa_executable_iterate_symbols; + core_api.hsa_executable_symbol_get_info_fn = + HSA::hsa_executable_symbol_get_info; + // Deprecated since v1.1. + core_api.hsa_executable_iterate_symbols_fn = + HSA::hsa_executable_iterate_symbols; + + //===--- Runtime Notifications ------------------------------------------===// + core_api.hsa_status_string_fn = HSA::hsa_status_string; + + //Start HSA v1.1 additions + core_api.hsa_extension_get_name_fn = HSA::hsa_extension_get_name; + core_api.hsa_system_major_extension_supported_fn = HSA::hsa_system_major_extension_supported; + core_api.hsa_system_get_major_extension_table_fn = HSA::hsa_system_get_major_extension_table; + core_api.hsa_agent_major_extension_supported_fn = HSA::hsa_agent_major_extension_supported; + core_api.hsa_cache_get_info_fn = HSA::hsa_cache_get_info; + core_api.hsa_agent_iterate_caches_fn = HSA::hsa_agent_iterate_caches; + //Silent store optimization is present in all signal ops when no agents are sleeping. + core_api.hsa_signal_silent_store_relaxed_fn = HSA::hsa_signal_store_relaxed; + core_api.hsa_signal_silent_store_screlease_fn = HSA::hsa_signal_store_screlease; + core_api.hsa_signal_group_create_fn = HSA::hsa_signal_group_create; + core_api.hsa_signal_group_destroy_fn = HSA::hsa_signal_group_destroy; + core_api.hsa_signal_group_wait_any_scacquire_fn = HSA::hsa_signal_group_wait_any_scacquire; + core_api.hsa_signal_group_wait_any_relaxed_fn = HSA::hsa_signal_group_wait_any_relaxed; + + //===--- Instruction Set Architecture - HSA v1.1 additions --------------===// + + core_api.hsa_agent_iterate_isas_fn = HSA::hsa_agent_iterate_isas; + core_api.hsa_isa_get_info_alt_fn = HSA::hsa_isa_get_info_alt; + core_api.hsa_isa_get_exception_policies_fn = + HSA::hsa_isa_get_exception_policies; + core_api.hsa_isa_get_round_method_fn = HSA::hsa_isa_get_round_method; + core_api.hsa_wavefront_get_info_fn = HSA::hsa_wavefront_get_info; + core_api.hsa_isa_iterate_wavefronts_fn = HSA::hsa_isa_iterate_wavefronts; + + //===--- Code Objects (deprecated) - HSA v1.1 additions -----------------===// + + // Deprecated since v1.1. + core_api.hsa_code_object_get_symbol_from_name_fn = + HSA::hsa_code_object_get_symbol_from_name; + + //===--- Executable - HSA v1.1 additions --------------------------------===// + + core_api.hsa_code_object_reader_create_from_file_fn = + HSA::hsa_code_object_reader_create_from_file; + core_api.hsa_code_object_reader_create_from_memory_fn = + HSA::hsa_code_object_reader_create_from_memory; + core_api.hsa_code_object_reader_destroy_fn = + HSA::hsa_code_object_reader_destroy; + core_api.hsa_executable_create_alt_fn = HSA::hsa_executable_create_alt; + core_api.hsa_executable_load_program_code_object_fn = + HSA::hsa_executable_load_program_code_object; + core_api.hsa_executable_load_agent_code_object_fn = + HSA::hsa_executable_load_agent_code_object; + core_api.hsa_executable_validate_alt_fn = HSA::hsa_executable_validate_alt; + core_api.hsa_executable_get_symbol_by_name_fn = + HSA::hsa_executable_get_symbol_by_name; + core_api.hsa_executable_iterate_agent_symbols_fn = + HSA::hsa_executable_iterate_agent_symbols; + core_api.hsa_executable_iterate_program_symbols_fn = + HSA::hsa_executable_iterate_program_symbols; } // Update Api table for Amd Extensions. diff --git a/runtime/hsa-runtime/core/runtime/isa.cpp b/runtime/hsa-runtime/core/runtime/isa.cpp index f8d74ca57a..363d6c20d5 100644 --- a/runtime/hsa-runtime/core/runtime/isa.cpp +++ b/runtime/hsa-runtime/core/runtime/isa.cpp @@ -47,6 +47,24 @@ namespace core { +bool Wavefront::GetInfo( + const hsa_wavefront_info_t &attribute, + void *value) const { + if (!value) { + return false; + } + + switch (attribute) { + case HSA_WAVEFRONT_INFO_SIZE: { + *((uint32_t*)value) = 64; + return true; + } + default: { + return false; + } + } +} + std::string Isa::GetFullName() const { std::stringstream full_name; full_name << GetVendor() << ":" << GetArchitecture() << ":" @@ -63,27 +81,82 @@ bool Isa::GetInfo(const hsa_isa_info_t &attribute, void *value) const { switch (attribute) { case HSA_ISA_INFO_NAME_LENGTH: { std::string full_name = GetFullName(); - *((uint32_t *)value) = static_cast(full_name.size()); + *((uint32_t*)value) = static_cast(full_name.size() + 1); return true; } case HSA_ISA_INFO_NAME: { std::string full_name = GetFullName(); + memset(value, 0x0, full_name.size() + 1); memcpy(value, full_name.c_str(), full_name.size()); return true; } - // @todo: following case needs to be removed. + // deprecated. case HSA_ISA_INFO_CALL_CONVENTION_COUNT: { - *((uint32_t *)value) = 1; + *((uint32_t*)value) = 1; return true; } - // @todo: following case needs to be removed. + // deprecated. case HSA_ISA_INFO_CALL_CONVENTION_INFO_WAVEFRONT_SIZE: { - *((uint32_t *)value) = 64; + *((uint32_t*)value) = 64; return true; } - // @todo: following needs to be removed. + // deprecated. case HSA_ISA_INFO_CALL_CONVENTION_INFO_WAVEFRONTS_PER_COMPUTE_UNIT: { - *((uint32_t *)value) = 40; + *((uint32_t*)value) = 40; + return true; + } + case HSA_ISA_INFO_MACHINE_MODELS: { + const bool machine_models[2] = {false, true}; + memcpy(value, machine_models, sizeof(machine_models)); + return true; + } + case HSA_ISA_INFO_PROFILES: { + bool profiles[2] = {true, false}; + if (this->version() == Version(7, 0, 0) || + this->version() == Version(8, 0, 1)) { + profiles[1] = true; + } + memcpy(value, profiles, sizeof(profiles)); + return true; + } + case HSA_ISA_INFO_DEFAULT_FLOAT_ROUNDING_MODES: { + const bool rounding_modes[3] = {false, false, true}; + memcpy(value, rounding_modes, sizeof(rounding_modes)); + return true; + } + case HSA_ISA_INFO_BASE_PROFILE_DEFAULT_FLOAT_ROUNDING_MODES: { + const bool rounding_modes[3] = {false, false, true}; + memcpy(value, rounding_modes, sizeof(rounding_modes)); + return true; + } + case HSA_ISA_INFO_FAST_F16_OPERATION: { + if (this->GetMajorVersion() >= 8) { + *((bool*)value) = true; + } else { + *((bool*)value) = false; + } + return true; + } + case HSA_ISA_INFO_WORKGROUP_MAX_DIM: { + const uint16_t workgroup_max_dim[3] = {1024, 1024, 1024}; + memcpy(value, workgroup_max_dim, sizeof(workgroup_max_dim)); + return true; + } + case HSA_ISA_INFO_WORKGROUP_MAX_SIZE: { + *((uint32_t*)value) = 1024; + return true; + } + case HSA_ISA_INFO_GRID_MAX_DIM: { + const hsa_dim3_t grid_max_dim = {UINT32_MAX, UINT32_MAX, UINT32_MAX}; + memcpy(value, &grid_max_dim, sizeof(grid_max_dim)); + return true; + } + case HSA_ISA_INFO_GRID_MAX_SIZE: { + *((uint64_t*)value) = UINT64_MAX; + return true; + } + case HSA_ISA_INFO_FBARRIER_MAX_SIZE: { + *((uint32_t*)value) = 32; return true; } default: { @@ -92,6 +165,12 @@ bool Isa::GetInfo(const hsa_isa_info_t &attribute, void *value) const { } } +hsa_round_method_t Isa::GetRoundMethod( + hsa_fp_type_t fp_type, + hsa_flush_mode_t flush_mode) const { + return HSA_ROUND_METHOD_SINGLE; +} + const Isa *IsaRegistry::GetIsa(const std::string &full_name) { auto isareg_iter = supported_isas_.find(full_name); return isareg_iter == supported_isas_.end() ? nullptr : &isareg_iter->second; @@ -117,11 +196,9 @@ const IsaRegistry::IsaMap IsaRegistry::GetSupportedIsas() { ISAREG_ENTRY_GEN(7, 0, 0) ISAREG_ENTRY_GEN(7, 0, 1) - ISAREG_ENTRY_GEN(8, 0, 0) ISAREG_ENTRY_GEN(8, 0, 1) ISAREG_ENTRY_GEN(8, 0, 2) ISAREG_ENTRY_GEN(8, 0, 3) - ISAREG_ENTRY_GEN(8, 1, 0) ISAREG_ENTRY_GEN(9, 0, 0) return supported_isas; diff --git a/runtime/hsa-runtime/core/runtime/runtime.cpp b/runtime/hsa-runtime/core/runtime/runtime.cpp index 26fb117b56..9229cedb04 100644 --- a/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -63,7 +63,7 @@ #include "core/inc/hsa_api_trace_int.h" #define HSA_VERSION_MAJOR 1 -#define HSA_VERSION_MINOR 0 +#define HSA_VERSION_MINOR 1 const char rocrbuildid[] = "ROCR BUILD ID: " STRING(ROCR_BUILD_ID); @@ -526,19 +526,23 @@ hsa_status_t Runtime::GetSystemInfo(hsa_system_info_t attribute, void* value) { #endif break; case HSA_SYSTEM_INFO_EXTENSIONS: - memset(value, 0, sizeof(uint8_t) * 128); + { + memset(value, 0, sizeof(uint8_t) * 128); - if (hsa_internal_api_table_.finalizer_api.hsa_ext_program_finalize_fn != NULL) { - *((uint8_t*)value) = 1 << HSA_EXTENSION_FINALIZER; + auto setFlag = [&](uint32_t bit) { assert(bit<128*8 && "Extension value exceeds extension bitmask"); uint index = bit/8; uint subBit = bit%8; ((uint8_t*)value)[index] |= 1<(hsa_signals); + reinterpret_cast(const_cast(hsa_signals)); uint32_t prior = 0; for (uint32_t i = 0; i < signal_count; i++) prior = Max(prior, atomic::Increment(&signals[i]->waiting_)); @@ -182,6 +182,18 @@ uint32_t Signal::WaitAny(uint32_t signal_count, hsa_signal_t* hsa_signals, } } +SignalGroup::SignalGroup(uint32_t num_signals, const hsa_signal_t* hsa_signals) : count(num_signals) +{ + if(count!=0) + signals=new hsa_signal_t[count]; + else + signals=NULL; + if(signals==NULL) + return; + for(int i=0; i /* size_t */ -#include /* uintXX_t */ +#include /* size_t */ +#include /* uintXX_t */ + #ifndef __cplusplus -#include +#include /* bool */ #endif /* __cplusplus */ // Placeholder for calling convention and import/export macros @@ -61,7 +62,6 @@ #define HSA_EXPORT_DECORATOR #endif #endif - #define HSA_API_EXPORT HSA_EXPORT_DECORATOR HSA_CALL #define HSA_API_IMPORT HSA_CALL @@ -93,9 +93,20 @@ #error "BIGENDIAN_CPU or LITTLEENDIAN_CPU must be defined" #endif +#ifndef HSA_DEPRECATED +#define HSA_DEPRECATED +//#ifdef __GNUC__ +//#define HSA_DEPRECATED __attribute__((deprecated)) +//#else +//#define HSA_DEPRECATED __declspec(deprecated) +//#endif +#endif + +#define HSA_VERSION_1_0 1 + #ifdef __cplusplus extern "C" { -#endif /* __cplusplus */ +#endif /* __cplusplus */ /** \defgroup status Runtime Notifications * @{ @@ -105,115 +116,148 @@ extern "C" { * @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 + /** + * 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 in a hardware exception. + */ + HSA_STATUS_ERROR_EXCEPTION = 0x1016, + /** + * The code object symbol is invalid. + */ + HSA_STATUS_ERROR_INVALID_CODE_SYMBOL = 0x1018, + /** + * The executable symbol is invalid. + */ + HSA_STATUS_ERROR_INVALID_EXECUTABLE_SYMBOL = 0x1019, + /** + * The file descriptor is invalid. + */ + HSA_STATUS_ERROR_INVALID_FILE = 0x1020, + /** + * The code object reader is invalid. + */ + HSA_STATUS_ERROR_INVALID_CODE_OBJECT_READER = 0x1021, + /** + * The cache is invalid. + */ + HSA_STATUS_ERROR_INVALID_CACHE = 0x1022, + /** + * The wavefront is invalid. + */ + HSA_STATUS_ERROR_INVALID_WAVEFRONT = 0x1023, + /** + * The signal group is invalid. + */ + HSA_STATUS_ERROR_INVALID_SIGNAL_GROUP = 0x1024, + /** + * The HSA runtime is not in the configuration state. + */ + HSA_STATUS_ERROR_INVALID_RUNTIME_STATE = 0x1025 + } hsa_status_t; /** @@ -232,8 +276,9 @@ typedef enum { * @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); +hsa_status_t HSA_API hsa_status_string( + hsa_status_t status, + const char ** status_string); /** @} */ @@ -248,17 +293,17 @@ typedef struct hsa_dim3_s { /** * X dimension. */ - uint32_t x; + uint32_t x; /** * Y dimension. */ - uint32_t y; + uint32_t y; - /** - * Z dimension. - */ - uint32_t z; + /** + * Z dimension. + */ + uint32_t z; } hsa_dim3_t; /** @@ -279,8 +324,14 @@ typedef enum { HSA_ACCESS_PERMISSION_RW = 3 } hsa_access_permission_t; +/** + * @brief POSIX file descriptor. + */ +typedef int hsa_file_t; + /** @} **/ + /** \defgroup initshutdown Initialization and Shut Down * @{ */ @@ -296,8 +347,8 @@ typedef enum { * * @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_OUT_OF_RESOURCES The HSA runtime failed to allocate + * the required resources. * * @retval ::HSA_STATUS_ERROR_REFCOUNT_OVERFLOW The HSA runtime reference * count reaches INT32_MAX. @@ -337,14 +388,14 @@ hsa_status_t HSA_API hsa_shut_down(); * 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 + /** + * 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; /** @@ -352,31 +403,31 @@ typedef enum { * 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 + /** + * 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 + * 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 + /** + * Base profile. + */ + HSA_PROFILE_BASE = 0, + /** + * Full profile. + */ + HSA_PROFILE_FULL = 1 } hsa_profile_t; /** @@ -409,7 +460,7 @@ typedef enum { */ HSA_SYSTEM_INFO_SIGNAL_MAX_WAIT = 4, /** - * Endianness of the system. The type of this attribute us ::hsa_endianness_t. + * Endianness of the system. The type of this attribute is ::hsa_endianness_t. */ HSA_SYSTEM_INFO_ENDIANNESS = 5, /** @@ -442,8 +493,9 @@ typedef enum { * @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); +hsa_status_t HSA_API hsa_system_get_info( + hsa_system_info_t attribute, + void* value); /** * @brief HSA extensions. @@ -457,21 +509,63 @@ typedef enum { * Images extension. */ HSA_EXTENSION_IMAGES = 1, + /** - * Profiler extension. + * Performance counter extension. */ - HSA_EXTENSION_AMD_PROFILER = 2, + HSA_EXTENSION_PERFORMANCE_COUNTERS = 2, + /** - * Loader extension. + * Profiling events extension. */ - HSA_EXTENSION_AMD_LOADER = 3, + HSA_EXTENSION_PROFILING_EVENTS = 3, /** * Extension count. */ - HSA_EXTENSION_COUNT + HSA_EXTENSION_STD_LAST = 3, + /** + * First AMD extension number. + */ + HSA_AMD_FIRST_EXTENSION = 0x200, + /** + * Profiler extension. + */ + HSA_EXTENSION_AMD_PROFILER = 0x200, + /** + * Loader extension. + */ + HSA_EXTENSION_AMD_LOADER = 0x201, + /** + * Last AMD extension. + */ + HSA_AMD_LAST_EXTENSION = 0x201 } hsa_extension_t; /** + * @brief Query the name of a given extension. + * + * @param[in] extension Extension identifier. If the extension is not supported + * by the implementation (see ::HSA_SYSTEM_INFO_EXTENSIONS), the behavior + * is undefined. + * + * @param[out] name Pointer to a memory location where the HSA runtime stores + * the extension name. The extension name is a NUL-terminated string. + * + * @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 name is NULL. + */ +hsa_status_t HSA_API hsa_extension_get_name( + uint16_t extension, + const char **name); + +/** + * @deprecated + * * @brief Query if a given version of an extension is supported by the HSA * implementation. * @@ -493,11 +587,45 @@ typedef enum { * @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); +hsa_status_t HSA_API HSA_DEPRECATED hsa_system_extension_supported( + uint16_t extension, + uint16_t version_major, + uint16_t version_minor, + bool* result); /** + * @brief Query if a given version of an extension is supported by the HSA + * implementation. All minor versions from 0 up to the returned @p version_minor + * must be supported by the implementation. + * + * @param[in] extension Extension identifier. + * + * @param[in] version_major Major version number. + * + * @param[out] 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 version_minor is NULL, or @p result is NULL. + */ +hsa_status_t HSA_API hsa_system_major_extension_supported( + uint16_t extension, + uint16_t version_major, + uint16_t *version_minor, + bool* result); + + +/** + * @deprecated + * * @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 @@ -528,19 +656,62 @@ hsa_status_t HSA_API * @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); +hsa_status_t HSA_API HSA_DEPRECATED 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 + * @brief Retrieve the function pointers corresponding to a given major 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 major + * version of the extension is supported by the HSA implementation (see + * ::hsa_system_major_extension_supported). If the given combination of extension + * and major version is not supported by the implementation, the behavior is + * undefined. Additionally if the length doesn't allow space for a full minor + * version, it is implementation defined if only some of the function pointers for + * that minor version get written. + * + * @param[in] extension Extension identifier. + * + * @param[in] version_major Major version number for which to retrieve the + * function pointer table. + * + * @param[in] table_length Size in bytes of the function pointer table to be + * populated. The implementation will not write more than this many bytes to the + * 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_major_extension_table( + uint16_t extension, + uint16_t version_major, + size_t table_length, + void *table); + +/** + * @brief Struct containing an opaque handle to 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. + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. */ uint64_t handle; } hsa_agent_t; @@ -549,33 +720,33 @@ typedef struct hsa_agent_s { * @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 + /** + * 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 + /** + * 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; /** @@ -604,15 +775,15 @@ typedef enum { */ 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. + * Agent name. The type of this attribute is a NUL-terminated char[64]. The + * name must be at most 63 characters long (not including the NUL terminator) + * and all array elements not used for the name must be NUL. */ 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. + * Name of vendor. The type of this attribute is a NUL-terminated char[64]. + * The name must be at most 63 characters long (not including the NUL + * terminator) and all array elements not used for the name must be NUL. */ HSA_AGENT_INFO_VENDOR_NAME = 1, /** @@ -620,29 +791,55 @@ typedef enum { */ HSA_AGENT_INFO_FEATURE = 2, /** + * @deprecated Query ::HSA_ISA_INFO_MACHINE_MODELS for a given intruction set + * architecture supported by the agent instead. If more than one ISA is + * supported by the agent, the returned value corresponds to the first ISA + * enumerated by ::hsa_agent_iterate_isas. + * * Machine model supported by the agent. The type of this attribute is * ::hsa_machine_model_t. */ HSA_AGENT_INFO_MACHINE_MODEL = 3, /** + * @deprecated Query ::HSA_ISA_INFO_PROFILES for a given intruction set + * architecture supported by the agent instead. If more than one ISA is + * supported by the agent, the returned value corresponds to the first ISA + * enumerated by ::hsa_agent_iterate_isas. + * * Profile supported by the agent. The type of this attribute is * ::hsa_profile_t. */ HSA_AGENT_INFO_PROFILE = 4, /** + * @deprecated Query ::HSA_ISA_INFO_DEFAULT_FLOAT_ROUNDING_MODES for a given + * intruction set architecture supported by the agent instead. If more than + * one ISA is supported by the agent, the returned value corresponds to the + * first ISA enumerated by ::hsa_agent_iterate_isas. + * * 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. + * @deprecated Query ::HSA_ISA_INFO_BASE_PROFILE_DEFAULT_FLOAT_ROUNDING_MODES + * for a given intruction set architecture supported by the agent instead. If + * more than one ISA is supported by the agent, the returned value corresponds + * to the first ISA enumerated by ::hsa_agent_iterate_isas. + * + * A bit-mask of ::hsa_default_float_rounding_mode_t values, representing the + * default floating-point rounding modes supported by the agent in the Base + * profile. The type of this attribute is uint32_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, /** + * @deprecated Query ::HSA_ISA_INFO_FAST_F16_OPERATION for a given intruction + * set architecture supported by the agent instead. If more than one ISA is + * supported by the agent, the returned value corresponds to the first ISA + * enumerated by ::hsa_agent_iterate_isas. + * * 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 @@ -650,12 +847,23 @@ typedef enum { */ HSA_AGENT_INFO_FAST_F16_OPERATION = 24, /** + * @deprecated Query ::HSA_WAVEFRONT_INFO_SIZE for a given wavefront and + * intruction set architecture supported by the agent instead. If more than + * one ISA is supported by the agent, the returned value corresponds to the + * first ISA enumerated by ::hsa_agent_iterate_isas and the first wavefront + * enumerated by ::hsa_isa_iterate_wavefronts for that ISA. + * * 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, /** + * @deprecated Query ::HSA_ISA_INFO_WORKGROUP_MAX_DIM for a given intruction + * set architecture supported by the agent instead. If more than one ISA is + * supported by the agent, the returned value corresponds to the first ISA + * enumerated by ::hsa_agent_iterate_isas. + * * 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 @@ -664,33 +872,53 @@ typedef enum { */ HSA_AGENT_INFO_WORKGROUP_MAX_DIM = 7, /** + * @deprecated Query ::HSA_ISA_INFO_WORKGROUP_MAX_SIZE for a given intruction + * set architecture supported by the agent instead. If more than one ISA is + * supported by the agent, the returned value corresponds to the first ISA + * enumerated by ::hsa_agent_iterate_isas. + * * 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, /** + * @deprecated Query ::HSA_ISA_INFO_GRID_MAX_DIM for a given intruction set + * architecture supported by the agent instead. + * * 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_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, /** + * @deprecated Query ::HSA_ISA_INFO_GRID_MAX_SIZE for a given intruction set + * architecture supported by the agent instead. If more than one ISA is + * supported by the agent, the returned value corresponds to the first ISA + * enumerated by ::hsa_agent_iterate_isas. + * * 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, /** + * @deprecated Query ::HSA_ISA_INFO_FBARRIER_MAX_SIZE for a given intruction + * set architecture supported by the agent instead. If more than one ISA is + * supported by the agent, the returned value corresponds to the first ISA + * enumerated by ::hsa_agent_iterate_isas. + * * 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, /** + * @deprecated The maximum number of queues is not statically determined. + * * 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. */ @@ -714,6 +942,8 @@ typedef enum { */ HSA_AGENT_INFO_QUEUE_TYPE = 15, /** + * @deprecated NUMA information is not exposed anywhere else in the API. + * * Identifier of the NUMA node associated with the agent. The type of this * attribute is uint32_t. */ @@ -724,12 +954,20 @@ typedef enum { */ HSA_AGENT_INFO_DEVICE = 17, /** + * @deprecated Query ::hsa_agent_iterate_caches to retrieve information about + * the caches present in a given agent. + * * 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, /** + * @deprecated An agent may support multiple instruction set + * architectures. See ::hsa_agent_iterate_isas. If more than one ISA is + * supported by the agent, the returned value corresponds to the first ISA + * enumerated by ::hsa_agent_iterate_isas. + * * Instruction set architecture of the agent. The type of this attribute * is ::hsa_isa_t. */ @@ -750,6 +988,7 @@ typedef enum { * agent. The type of this attribute is uint16_t. */ HSA_AGENT_INFO_VERSION_MINOR = 22 + } hsa_agent_info_t; /** @@ -773,16 +1012,17 @@ typedef enum { * @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); +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 + * 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. @@ -796,10 +1036,10 @@ hsa_status_t HSA_API hsa_agent_get_info(hsa_agent_t agent, * 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); +*/ +hsa_status_t HSA_API hsa_iterate_agents( + hsa_status_t (*callback)(hsa_agent_t agent, void* data), + void* data); /* @@ -823,17 +1063,22 @@ hsa_status_t HSA_API hsa_agent_set_info( * @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 + /** + * 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; /** + * @deprecated Use ::hsa_isa_get_exception_policies for a given intruction set + * architecture supported by the agent instead. If more than one ISA is + * supported by the agent, this function uses the first value returned by + * ::hsa_agent_iterate_isas. + * * @brief Retrieve the exception policy support for a given combination of * agent and profile * @@ -855,11 +1100,111 @@ typedef enum { * 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); +hsa_status_t HSA_API HSA_DEPRECATED hsa_agent_get_exception_policies( + hsa_agent_t agent, + hsa_profile_t profile, + uint16_t *mask); /** + * @brief Cache handle. + */ +typedef struct hsa_cache_s { + /** + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. + */ + uint64_t handle; +} hsa_cache_t; + +/** + * @brief Cache attributes. + */ +typedef enum { + /** + * The length of the cache name in bytes, not including the NUL terminator. + * The type of this attribute is uint32_t. + */ + HSA_CACHE_INFO_NAME_LENGTH = 0, + /** + * Human-readable description. The type of this attribute is a NUL-terminated + * character array with the length equal to the value of + * ::HSA_CACHE_INFO_NAME_LENGTH attribute. + */ + HSA_CACHE_INFO_NAME = 1, + /** + * Cache level. A L1 cache must return a value of 1, a L2 must return a value + * of 2, and so on. The type of this attribute is uint8_t. + */ + HSA_CACHE_INFO_LEVEL = 2, + /** + * Cache size, in bytes. A value of 0 indicates that there is no size + * information available. The type of this attribute is uint32_t. + */ + HSA_CACHE_INFO_SIZE = 3 +} hsa_cache_info_t; + +/** + * @brief Get the current value of an attribute for a given cache object. + * + * @param[in] cache Cache. + * + * @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_CACHE The cache is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p attribute is an invalid + * instruction set architecture attribute, or @p value is + * NULL. + */ +hsa_status_t HSA_API hsa_cache_get_info( + hsa_cache_t cache, + hsa_cache_info_t attribute, + void* value); + +/** + * @brief Iterate over the memory caches of a given agent, and + * invoke an application-defined callback on every iteration. + * + * @details Caches are visited in ascending order according to the value of the + * ::HSA_CACHE_INFO_LEVEL attribute. + * + * @param[in] agent A valid agent. + * + * @param[in] callback Callback to be invoked once per cache that is present in + * the agent. The HSA runtime passes two arguments to the callback: the cache + * and the application data. If @p callback returns a status other than + * ::HSA_STATUS_SUCCESS for a particular iteration, the traversal stops and + * that value is returned. + * + * @param[in] data Application data that is passed to @p callback on every + * iteration. May be NULL. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL. + */ +hsa_status_t HSA_API hsa_agent_iterate_caches( + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_cache_t cache, void* data), + void* data); + +/** + * @deprecated + * * @brief Query if a given version of an extension is supported by an agent * * @param[in] extension Extension identifier. @@ -872,7 +1217,9 @@ hsa_status_t HSA_API hsa_agent_get_exception_policies(hsa_agent_t agent, * * @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. + * extension is supported, and false otherwise. The result must be false if + * ::hsa_system_extension_supported returns false for the same extension + * version. * * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. * @@ -884,13 +1231,52 @@ hsa_status_t HSA_API hsa_agent_get_exception_policies(hsa_agent_t agent, * @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); +hsa_status_t HSA_API HSA_DEPRECATED hsa_agent_extension_supported( + uint16_t extension, + hsa_agent_t agent, + uint16_t version_major, + uint16_t version_minor, + bool* result); + +/** + * @brief Query if a given version of an extension is supported by an agent. All + * minor versions from 0 up to the returned @p version_minor must be supported. + * + * @param[in] extension Extension identifier. + * + * @param[in] agent Agent. + * + * @param[in] version_major Major version number. + * + * @param[out] 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. The result must be false if + * ::hsa_system_extension_supported returns false for the same extension + * version. + * + * @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 version_minor is NULL, or @p result is NULL. + */ +hsa_status_t HSA_API hsa_agent_major_extension_supported( + uint16_t extension, + hsa_agent_t agent, + uint16_t version_major, + uint16_t *version_minor, + bool* result); + /** @} */ + /** \defgroup signals Signals * @{ */ @@ -900,7 +1286,8 @@ hsa_status_t HSA_API */ typedef struct hsa_signal_s { /** - * Opaque handle. The value 0 is reserved. + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. The value 0 is reserved. */ uint64_t handle; } hsa_signal_t; @@ -910,9 +1297,9 @@ typedef struct hsa_signal_s { * bits in large machine mode. */ #ifdef HSA_LARGE_MODEL -typedef int64_t hsa_signal_value_t; + typedef int64_t hsa_signal_value_t; #else -typedef int32_t hsa_signal_value_t; + typedef int32_t hsa_signal_value_t; #endif /** @@ -931,23 +1318,25 @@ typedef int32_t hsa_signal_value_t; * 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. + * store the newly created signal handle. Must not be NULL. * * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. * * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been * initialized. * - * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES There is failure to allocate the - * resources required by the implementation. + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to allocate + * the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p signal is NULL, @p * num_consumers is greater than 0 but @p consumers is NULL, or @p consumers * contains duplicates. */ -hsa_status_t HSA_API - hsa_signal_create(hsa_signal_value_t initial_value, uint32_t num_consumers, - const hsa_agent_t *consumers, hsa_signal_t *signal); +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. @@ -963,7 +1352,8 @@ hsa_status_t HSA_API * * @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); +hsa_status_t HSA_API hsa_signal_destroy( + hsa_signal_t signal); /** * @brief Atomically read the current value of a signal. @@ -971,13 +1361,23 @@ hsa_status_t HSA_API hsa_signal_destroy(hsa_signal_t signal); * @param[in] signal Signal. * * @return Value of the signal. - */ -hsa_signal_value_t HSA_API hsa_signal_load_acquire(hsa_signal_t signal); +*/ +hsa_signal_value_t HSA_API hsa_signal_load_scacquire( + hsa_signal_t signal); /** - * @copydoc hsa_signal_load_acquire + * @copydoc hsa_signal_load_scacquire */ -hsa_signal_value_t HSA_API hsa_signal_load_relaxed(hsa_signal_t signal); +hsa_signal_value_t HSA_API hsa_signal_load_relaxed( + hsa_signal_t signal); + +/** + * @deprecated Renamed as ::hsa_signal_load_scacquire. + * + * @copydoc hsa_signal_load_scacquire +*/ +hsa_signal_value_t HSA_API HSA_DEPRECATED hsa_signal_load_acquire( + hsa_signal_t signal); /** * @brief Atomically set the value of a signal. @@ -989,14 +1389,49 @@ hsa_signal_value_t HSA_API hsa_signal_load_relaxed(hsa_signal_t signal); * * @param[in] value New signal value. */ -void HSA_API - hsa_signal_store_relaxed(hsa_signal_t signal, hsa_signal_value_t 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); +void HSA_API hsa_signal_store_screlease( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @deprecated Renamed as ::hsa_signal_store_screlease. + * + * @copydoc hsa_signal_store_screlease + */ +void HSA_API HSA_DEPRECATED hsa_signal_store_release( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @brief Atomically set the value of a signal without necessarily notifying the + * the agents waiting on it. + * + * @details The agents waiting on @p signal may not wake up even when the new + * value satisfies their wait condition. If the application wants to update the + * signal and there is no need to notify any agent, invoking this function can + * be more efficient than calling the non-silent counterpart. + * + * @param[in] signal Signal. + * + * @param[in] value New signal value. + */ +void HSA_API hsa_signal_silent_store_relaxed( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_silent_store_relaxed + */ +void HSA_API hsa_signal_silent_store_screlease( + hsa_signal_t signal, + hsa_signal_value_t value); /** * @brief Atomically set the value of a signal and return its previous value. @@ -1012,26 +1447,56 @@ void HSA_API * @return Value of the signal prior to the exchange. * */ -hsa_signal_value_t HSA_API - hsa_signal_exchange_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); +hsa_signal_value_t HSA_API hsa_signal_exchange_scacq_screl( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_exchange_acq_rel + * @deprecated Renamed as ::hsa_signal_exchange_scacq_screl. + * + * @copydoc hsa_signal_exchange_scacq_screl */ -hsa_signal_value_t HSA_API - hsa_signal_exchange_acquire(hsa_signal_t signal, hsa_signal_value_t value); +hsa_signal_value_t HSA_API HSA_DEPRECATED hsa_signal_exchange_acq_rel( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_exchange_acq_rel + * @copydoc hsa_signal_exchange_scacq_screl */ -hsa_signal_value_t HSA_API - hsa_signal_exchange_relaxed(hsa_signal_t signal, hsa_signal_value_t value); +hsa_signal_value_t HSA_API hsa_signal_exchange_scacquire( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_exchange_acq_rel + * @deprecated Renamed as ::hsa_signal_exchange_scacquire. + * + * @copydoc hsa_signal_exchange_scacquire */ -hsa_signal_value_t HSA_API - hsa_signal_exchange_release(hsa_signal_t signal, hsa_signal_value_t value); +hsa_signal_value_t HSA_API HSA_DEPRECATED hsa_signal_exchange_acquire( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_exchange_scacq_screl + */ +hsa_signal_value_t HSA_API hsa_signal_exchange_relaxed( + hsa_signal_t signal, + hsa_signal_value_t value); +/** + * @copydoc hsa_signal_exchange_scacq_screl + */ +hsa_signal_value_t HSA_API hsa_signal_exchange_screlease( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @deprecated Renamed as ::hsa_signal_exchange_screlease. + * + * @copydoc hsa_signal_exchange_screlease + */ +hsa_signal_value_t HSA_API HSA_DEPRECATED hsa_signal_exchange_release( + hsa_signal_t signal, + hsa_signal_value_t value); /** * @brief Atomically set the value of a signal if the observed value is equal to @@ -1051,30 +1516,65 @@ hsa_signal_value_t HSA_API * @return Observed value of the signal. * */ -hsa_signal_value_t HSA_API hsa_signal_cas_acq_rel(hsa_signal_t signal, - hsa_signal_value_t expected, - hsa_signal_value_t value); +hsa_signal_value_t HSA_API hsa_signal_cas_scacq_screl( + hsa_signal_t signal, + hsa_signal_value_t expected, + hsa_signal_value_t value); + /** - * @copydoc hsa_signal_cas_acq_rel + * @deprecated Renamed as ::hsa_signal_cas_scacq_screl. + * + * @copydoc hsa_signal_cas_scacq_screl */ -hsa_signal_value_t HSA_API hsa_signal_cas_acquire(hsa_signal_t signal, - hsa_signal_value_t expected, - hsa_signal_value_t value); +hsa_signal_value_t HSA_API HSA_DEPRECATED hsa_signal_cas_acq_rel( + hsa_signal_t signal, + hsa_signal_value_t expected, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_cas_acq_rel + * @copydoc hsa_signal_cas_scacq_screl */ -hsa_signal_value_t HSA_API hsa_signal_cas_relaxed(hsa_signal_t signal, - hsa_signal_value_t expected, - hsa_signal_value_t value); +hsa_signal_value_t HSA_API hsa_signal_cas_scacquire( + hsa_signal_t signal, + hsa_signal_value_t expected, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_cas_acq_rel + * @deprecated Renamed as ::hsa_signal_cas_scacquire. + * + * @copydoc hsa_signal_cas_scacquire */ -hsa_signal_value_t HSA_API hsa_signal_cas_release(hsa_signal_t signal, - hsa_signal_value_t expected, - hsa_signal_value_t value); +hsa_signal_value_t HSA_API HSA_DEPRECATED hsa_signal_cas_acquire( + hsa_signal_t signal, + hsa_signal_value_t expected, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_cas_scacq_screl + */ +hsa_signal_value_t HSA_API hsa_signal_cas_relaxed( + hsa_signal_t signal, + hsa_signal_value_t expected, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_cas_scacq_screl + */ +hsa_signal_value_t HSA_API hsa_signal_cas_screlease( + hsa_signal_t signal, + hsa_signal_value_t expected, + hsa_signal_value_t value); + +/** + * @deprecated Renamed as ::hsa_signal_cas_screlease. + * + * @copydoc hsa_signal_cas_screlease + */ +hsa_signal_value_t HSA_API HSA_DEPRECATED hsa_signal_cas_release( + hsa_signal_t signal, + hsa_signal_value_t expected, + hsa_signal_value_t value); /** * @brief Atomically increment the value of a signal by a given amount. @@ -1088,26 +1588,58 @@ hsa_signal_value_t HSA_API hsa_signal_cas_release(hsa_signal_t signal, * @param[in] value Value to add to the value of the signal. * */ -void HSA_API - hsa_signal_add_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_add_scacq_screl( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_add_acq_rel + * @deprecated Renamed as ::hsa_signal_add_scacq_screl. + * + * @copydoc hsa_signal_add_scacq_screl */ -void HSA_API - hsa_signal_add_acquire(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_add_acq_rel( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_add_acq_rel + * @copydoc hsa_signal_add_scacq_screl */ -void HSA_API - hsa_signal_add_relaxed(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_add_scacquire( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_add_acq_rel + * @deprecated Renamed as ::hsa_signal_add_scacquire. + * + * @copydoc hsa_signal_add_scacquire */ -void HSA_API - hsa_signal_add_release(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_add_acquire( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_add_scacq_screl + */ +void HSA_API hsa_signal_add_relaxed( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_add_scacq_screl + */ +void HSA_API hsa_signal_add_screlease( + hsa_signal_t signal, + hsa_signal_value_t value); + + +/** + * @deprecated Renamed as ::hsa_signal_add_screlease. + * + * @copydoc hsa_signal_add_screlease + */ +void HSA_API HSA_DEPRECATED hsa_signal_add_release( + hsa_signal_t signal, + hsa_signal_value_t value); /** * @brief Atomically decrement the value of a signal by a given amount. @@ -1121,26 +1653,59 @@ void HSA_API * @param[in] value Value to subtract from the value of the signal. * */ -void HSA_API - hsa_signal_subtract_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_subtract_scacq_screl( + hsa_signal_t signal, + hsa_signal_value_t value); + /** - * @copydoc hsa_signal_subtract_acq_rel + * @deprecated Renamed as ::hsa_signal_subtract_scacq_screl. + * + * @copydoc hsa_signal_subtract_scacq_screl */ -void HSA_API - hsa_signal_subtract_acquire(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_subtract_acq_rel( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_subtract_acq_rel + * @copydoc hsa_signal_subtract_scacq_screl */ -void HSA_API - hsa_signal_subtract_relaxed(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_subtract_scacquire( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_subtract_acq_rel + * @deprecated Renamed as ::hsa_signal_subtract_scacquire. + * + * @copydoc hsa_signal_subtract_scacquire */ -void HSA_API - hsa_signal_subtract_release(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_subtract_acquire( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_subtract_scacq_screl + */ +void HSA_API hsa_signal_subtract_relaxed( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_subtract_scacq_screl + */ +void HSA_API hsa_signal_subtract_screlease( + hsa_signal_t signal, + hsa_signal_value_t value); + + +/** + * @deprecated Renamed as ::hsa_signal_subtract_screlease. + * + * @copydoc hsa_signal_subtract_screlease + */ +void HSA_API HSA_DEPRECATED hsa_signal_subtract_release( + hsa_signal_t signal, + hsa_signal_value_t value); /** * @brief Atomically perform a bitwise AND operation between the value of a @@ -1155,26 +1720,58 @@ void HSA_API * @param[in] value Value to AND with the value of the signal. * */ -void HSA_API - hsa_signal_and_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_and_scacq_screl( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_and_acq_rel + * @deprecated Renamed as ::hsa_signal_and_scacq_screl. + * + * @copydoc hsa_signal_and_scacq_screl */ -void HSA_API - hsa_signal_and_acquire(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_and_acq_rel( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_and_acq_rel + * @copydoc hsa_signal_and_scacq_screl */ -void HSA_API - hsa_signal_and_relaxed(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_and_scacquire( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_and_acq_rel + * @deprecated Renamed as ::hsa_signal_and_scacquire. + * + * @copydoc hsa_signal_and_scacquire */ -void HSA_API - hsa_signal_and_release(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_and_acquire( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_and_scacq_screl + */ +void HSA_API hsa_signal_and_relaxed( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_and_scacq_screl + */ +void HSA_API hsa_signal_and_screlease( + hsa_signal_t signal, + hsa_signal_value_t value); + + +/** + * @deprecated Renamed as ::hsa_signal_and_screlease. + * + * @copydoc hsa_signal_and_screlease + */ +void HSA_API HSA_DEPRECATED hsa_signal_and_release( + hsa_signal_t signal, + hsa_signal_value_t value); /** * @brief Atomically perform a bitwise OR operation between the value of a @@ -1188,26 +1785,58 @@ void HSA_API * * @param[in] value Value to OR with the value of the signal. */ -void HSA_API - hsa_signal_or_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_or_scacq_screl( + hsa_signal_t signal, + hsa_signal_value_t value); + /** - * @copydoc hsa_signal_or_acq_rel + * @deprecated Renamed as ::hsa_signal_or_scacq_screl. + * + * @copydoc hsa_signal_or_scacq_screl */ -void HSA_API - hsa_signal_or_acquire(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_or_acq_rel( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_or_acq_rel + * @copydoc hsa_signal_or_scacq_screl */ -void HSA_API - hsa_signal_or_relaxed(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_or_scacquire( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_or_acq_rel + * @deprecated Renamed as ::hsa_signal_or_scacquire. + * + * @copydoc hsa_signal_or_scacquire */ -void HSA_API - hsa_signal_or_release(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_or_acquire( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_or_scacq_screl + */ +void HSA_API hsa_signal_or_relaxed( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_or_scacq_screl + */ +void HSA_API hsa_signal_or_screlease( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @deprecated Renamed as ::hsa_signal_or_screlease. + * + * @copydoc hsa_signal_or_screlease + */ +void HSA_API HSA_DEPRECATED hsa_signal_or_release( + hsa_signal_t signal, + hsa_signal_value_t value); /** * @brief Atomically perform a bitwise XOR operation between the value of a @@ -1222,63 +1851,96 @@ void HSA_API * @param[in] value Value to XOR with the value of the signal. * */ -void HSA_API - hsa_signal_xor_acq_rel(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_xor_scacq_screl( + hsa_signal_t signal, + hsa_signal_value_t value); + /** - * @copydoc hsa_signal_xor_acq_rel + * @deprecated Renamed as ::hsa_signal_xor_scacq_screl. + * + * @copydoc hsa_signal_xor_scacq_screl */ -void HSA_API - hsa_signal_xor_acquire(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_xor_acq_rel( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_xor_acq_rel + * @copydoc hsa_signal_xor_scacq_screl */ -void HSA_API - hsa_signal_xor_relaxed(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API hsa_signal_xor_scacquire( + hsa_signal_t signal, + hsa_signal_value_t value); /** - * @copydoc hsa_signal_xor_acq_rel + * @deprecated Renamed as ::hsa_signal_xor_scacquire. + * + * @copydoc hsa_signal_xor_scacquire */ -void HSA_API - hsa_signal_xor_release(hsa_signal_t signal, hsa_signal_value_t value); +void HSA_API HSA_DEPRECATED hsa_signal_xor_acquire( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_xor_scacq_screl + */ +void HSA_API hsa_signal_xor_relaxed( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @copydoc hsa_signal_xor_scacq_screl + */ +void HSA_API hsa_signal_xor_screlease( + hsa_signal_t signal, + hsa_signal_value_t value); + +/** + * @deprecated Renamed as ::hsa_signal_xor_screlease. + * + * @copydoc hsa_signal_xor_screlease + */ +void HSA_API HSA_DEPRECATED hsa_signal_xor_release( + hsa_signal_t signal, + hsa_signal_value_t value); /** * @brief Wait condition operator. */ typedef enum { - /** - * The two operands are equal. - */ - HSA_SIGNAL_CONDITION_EQ = 0, - /** - * The two operands are not equal. - */ - HSA_SIGNAL_CONDITION_NE = 1, - /** - * The first operand is less than the second operand. - */ - HSA_SIGNAL_CONDITION_LT = 2, - /** - * The first operand is greater than or equal to the second operand. - */ - HSA_SIGNAL_CONDITION_GTE = 3 + /** + * The two operands are equal. + */ + HSA_SIGNAL_CONDITION_EQ = 0, + /** + * The two operands are not equal. + */ + HSA_SIGNAL_CONDITION_NE = 1, + /** + * The first operand is less than the second operand. + */ + HSA_SIGNAL_CONDITION_LT = 2, + /** + * The first operand is greater than or equal to the second operand. + */ + HSA_SIGNAL_CONDITION_GTE = 3 } hsa_signal_condition_t; /** * @brief State of the application thread during a signal wait. */ typedef enum { - /** - * The application thread may be rescheduled while waiting on the signal. - */ - HSA_WAIT_STATE_BLOCKED = 0, - /** - * The application thread stays active while waiting on a signal. - */ - HSA_WAIT_STATE_ACTIVE = 1 + /** + * The application thread may be rescheduled while waiting on the signal. + */ + HSA_WAIT_STATE_BLOCKED = 0, + /** + * The application thread stays active while waiting on a signal. + */ + HSA_WAIT_STATE_ACTIVE = 1 } hsa_wait_state_t; + /** * @brief Wait until a signal value satisfies a specified condition, or a * certain amount of time has elapsed. @@ -1317,23 +1979,166 @@ typedef enum { * @return Observed value of the signal, which might not satisfy the specified * condition. * - */ -hsa_signal_value_t HSA_API - hsa_signal_wait_acquire(hsa_signal_t signal, - hsa_signal_condition_t condition, - hsa_signal_value_t compare_value, - uint64_t timeout_hint, - hsa_wait_state_t wait_state_hint); +*/ +hsa_signal_value_t HSA_API hsa_signal_wait_scacquire( + hsa_signal_t signal, + hsa_signal_condition_t condition, + hsa_signal_value_t compare_value, + uint64_t timeout_hint, + hsa_wait_state_t wait_state_hint); /** - * @copydoc hsa_signal_wait_acquire + * @copydoc hsa_signal_wait_scacquire */ -hsa_signal_value_t HSA_API - hsa_signal_wait_relaxed(hsa_signal_t signal, - hsa_signal_condition_t condition, - hsa_signal_value_t compare_value, - uint64_t timeout_hint, - hsa_wait_state_t wait_state_hint); +hsa_signal_value_t HSA_API hsa_signal_wait_relaxed( + hsa_signal_t signal, + hsa_signal_condition_t condition, + hsa_signal_value_t compare_value, + uint64_t timeout_hint, + hsa_wait_state_t wait_state_hint); + +/** + * @deprecated Renamed as ::hsa_signal_wait_scacquire. + * + * @copydoc hsa_signal_wait_scacquire + */ +hsa_signal_value_t HSA_API HSA_DEPRECATED hsa_signal_wait_acquire( + hsa_signal_t signal, + hsa_signal_condition_t condition, + hsa_signal_value_t compare_value, + uint64_t timeout_hint, + hsa_wait_state_t wait_state_hint); + +/** + * @brief Group of signals. + */ +typedef struct hsa_signal_group_s { + /** + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. + */ + uint64_t handle; +} hsa_signal_group_t; + +/** + * @brief Create a signal group. + * + * @param[in] num_signals Number of elements in @p signals. Must not be 0. + * + * @param[in] signals List of signals in the group. The list must not contain + * any repeated elements. Must not be NULL. + * + * @param[in] num_consumers Number of elements in @p consumers. Must not be 0. + * + * @param[in] consumers List of agents that might consume (wait on) the signal + * group. The list must not contain repeated elements, and must be a subset of + * the set of agents that are allowed to wait on all the signals in the + * group. If an agent not listed in @p consumers waits on the returned group, + * the behavior is undefined. The memory associated with @p consumers can be + * reused or freed after the function returns. Must not be NULL. + * + * @param[out] signal_group Pointer to newly created signal group. Must not be + * NULL. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to allocate + * the required resources. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p num_signals is 0, @p signals + * is NULL, @p num_consumers is 0, @p consumers is NULL, or @p signal_group is + * NULL. + */ +hsa_status_t HSA_API hsa_signal_group_create( + uint32_t num_signals, + const hsa_signal_t *signals, + uint32_t num_consumers, + const hsa_agent_t *consumers, + hsa_signal_group_t *signal_group); + +/** + * @brief Destroy a signal group previous created by ::hsa_signal_group_create. + * + * @param[in] signal_group Signal group. + * + * @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_GROUP @p signal_group is invalid. + */ +hsa_status_t HSA_API hsa_signal_group_destroy( + hsa_signal_group_t signal_group); + +/** + * @brief Wait until the value of at least one of the signals in a signal group + * satisfies its associated condition. + * + * @details The function is guaranteed to return if the value of at least one of + * the signals in the group satisfies its associated condition at some point in + * time during the wait, but the signal value returned to the application may no + * longer satisfy the condition. The application must ensure that signals in the + * group are used in such way that wait wakeup conditions are not invalidated + * before dependent threads have woken up. + * + * When this operation internally loads the value of the passed signal, it uses + * the memory order indicated in the function name. + * + * @param[in] signal_group Signal group. + * + * @param[in] conditions List of conditions. Each condition, and the value at + * the same index in @p compare_values, is used to compare the value of the + * signal at that index in @p signal_group (the signal passed by the application + * to ::hsa_signal_group_create at that particular index). The size of @p + * conditions must not be smaller than the number of signals in @p signal_group; + * any extra elements are ignored. Must not be NULL. + * + * @param[in] compare_values List of comparison values. The size of @p + * compare_values must not be smaller than the number of signals in @p + * signal_group; any extra elements are ignored. Must not be NULL. + * + * @param[in] wait_state_hint Hint used by the application to indicate the + * preferred waiting state. The actual waiting state is decided by the HSA runtime + * and may not match the provided hint. A value of ::HSA_WAIT_STATE_ACTIVE may + * improve the latency of response to a signal update by avoiding rescheduling + * overhead. + * + * @param[out] signal Signal in the group that satisfied the associated + * condition. If several signals satisfied their condition, the function can + * return any of those signals. Must not be NULL. + * + * @param[out] value Observed value for @p signal, which might no longer satisfy + * the specified condition. Must not be NULL. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_INVALID_SIGNAL_GROUP @p signal_group is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p conditions is NULL, @p + * compare_values is NULL, @p signal is NULL, or @p value is NULL. + */ +hsa_status_t HSA_API hsa_signal_group_wait_any_scacquire( + hsa_signal_group_t signal_group, + const hsa_signal_condition_t *conditions, + const hsa_signal_value_t *compare_values, + hsa_wait_state_t wait_state_hint, + hsa_signal_t *signal, + hsa_signal_value_t *value); + +/** + * @copydoc hsa_signal_group_wait_any_scacquire + */ +hsa_status_t HSA_API hsa_signal_group_wait_any_relaxed( + hsa_signal_group_t signal_group, + const hsa_signal_condition_t *conditions, + const hsa_signal_value_t *compare_values, + hsa_wait_state_t wait_state_hint, + hsa_signal_t *signal, + hsa_signal_value_t *value); /** @} */ @@ -1349,13 +2154,15 @@ hsa_signal_value_t HSA_API */ typedef struct hsa_region_s { /** - * Opaque handle. + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. */ uint64_t handle; } hsa_region_t; /** @} */ + /** \defgroup queue Queues * @{ */ @@ -1370,11 +2177,19 @@ typedef enum { */ HSA_QUEUE_TYPE_MULTI = 0, /** - * Queue only supports a single producer. + * Queue only supports a single producer. In some scenarios, the application + * may want to limit the submission of AQL packets to a single agent. Queues + * that support a single producer may be more efficient than queues supporting + * multiple producers. */ HSA_QUEUE_TYPE_SINGLE = 1 } hsa_queue_type_t; +/** + * @brief A fixed-size type used to represent ::hsa_queue_type_t constants. + */ +typedef uint32_t hsa_queue_type32_t; + /** * @brief Queue features. */ @@ -1402,7 +2217,7 @@ typedef struct hsa_queue_s { /** * Queue type. */ - hsa_queue_type_t type; + hsa_queue_type32_t type; /** * Queue features mask. This is a bit-field of ::hsa_queue_feature_t @@ -1411,20 +2226,20 @@ typedef struct hsa_queue_s { uint32_t features; #ifdef HSA_LARGE_MODEL - void *base_address; + void* base_address; #elif defined HSA_LITTLE_ENDIAN /** * Starting address of the HSA runtime-allocated buffer used to store the AQL * packets. Must be aligned to the size of an AQL packet. */ - void *base_address; + void* base_address; /** * Reserved. Must be 0. */ uint32_t reserved0; #else uint32_t reserved0; - void *base_address; + void* base_address; #endif /** @@ -1433,7 +2248,7 @@ typedef struct hsa_queue_s { * the application tries to replace or destroy this signal, the behavior is * undefined. * - * If @a type is ::HSA_QUEUE_TYPE_SINGLE the doorbell signal value must be + * If @a type is ::HSA_QUEUE_TYPE_SINGLE, the doorbell signal value must be * updated in a monotonically increasing fashion. If @a type is * ::HSA_QUEUE_TYPE_MULTI, the doorbell signal value can be updated with any * value. @@ -1513,8 +2328,8 @@ typedef struct hsa_queue_s { * @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_OUT_OF_RESOURCES The HSA runtime failed to allocate + * the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid. * @@ -1525,12 +2340,15 @@ typedef struct hsa_queue_s { * @p size is 0, @p type is an invalid queue type, or @p queue is NULL. * */ -hsa_status_t HSA_API - hsa_queue_create(hsa_agent_t agent, uint32_t size, hsa_queue_type_t type, - void (*callback)(hsa_status_t status, hsa_queue_t *source, - void *data), - void *data, uint32_t private_segment_size, - uint32_t group_segment_size, hsa_queue_t **queue); +hsa_status_t HSA_API hsa_queue_create( + hsa_agent_t agent, + uint32_t size, + hsa_queue_type_t type, + void (*callback)(hsa_status_t status, hsa_queue_t *source, void *data), + void *data, + uint32_t private_segment_size, + uint32_t group_segment_size, + hsa_queue_t **queue); /** * @brief Create a queue for which the application or a kernel is responsible @@ -1578,18 +2396,21 @@ hsa_status_t HSA_API * @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_OUT_OF_RESOURCES The HSA runtime failed to allocate + * the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p size is not a power of two, @p * size is 0, @p type is an invalid queue type, the doorbell signal handle is * 0, or @p queue is NULL. * */ -hsa_status_t HSA_API - hsa_soft_queue_create(hsa_region_t region, uint32_t size, - hsa_queue_type_t type, uint32_t features, - hsa_signal_t doorbell_signal, hsa_queue_t **queue); +hsa_status_t HSA_API hsa_soft_queue_create( + hsa_region_t region, + uint32_t size, + hsa_queue_type_t type, + uint32_t features, + hsa_signal_t doorbell_signal, + hsa_queue_t **queue); /** * @brief Destroy a user mode queue. @@ -1614,7 +2435,8 @@ hsa_status_t HSA_API * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p queue is NULL. */ -hsa_status_t HSA_API hsa_queue_destroy(hsa_queue_t *queue); +hsa_status_t HSA_API hsa_queue_destroy( + hsa_queue_t *queue); /** * @brief Inactivate a queue. @@ -1634,7 +2456,16 @@ hsa_status_t HSA_API hsa_queue_destroy(hsa_queue_t *queue); * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p queue is NULL. */ -hsa_status_t HSA_API hsa_queue_inactivate(hsa_queue_t *queue); +hsa_status_t HSA_API hsa_queue_inactivate( + hsa_queue_t *queue); + +/** + * @deprecated Renamed as ::hsa_queue_load_read_index_scacquire. + * + * @copydoc hsa_queue_load_read_index_scacquire + */ +uint64_t HSA_API HSA_DEPRECATED hsa_queue_load_read_index_acquire( + const hsa_queue_t *queue); /** * @brief Atomically load the read index of a queue. @@ -1643,12 +2474,22 @@ hsa_status_t HSA_API hsa_queue_inactivate(hsa_queue_t *queue); * * @return Read index of the queue pointed by @p queue. */ -uint64_t HSA_API hsa_queue_load_read_index_acquire(const hsa_queue_t *queue); +uint64_t HSA_API hsa_queue_load_read_index_scacquire( + const hsa_queue_t *queue); /** - * @copydoc hsa_queue_load_read_index_acquire + * @copydoc hsa_queue_load_read_index_scacquire */ -uint64_t HSA_API hsa_queue_load_read_index_relaxed(const hsa_queue_t *queue); +uint64_t HSA_API hsa_queue_load_read_index_relaxed( + const hsa_queue_t *queue); + +/** + * @deprecated Renamed as ::hsa_queue_load_write_index_scacquire. + * + * @copydoc hsa_queue_load_write_index_scacquire + */ +uint64_t HSA_API HSA_DEPRECATED hsa_queue_load_write_index_acquire( + const hsa_queue_t *queue); /** * @brief Atomically load the write index of a queue. @@ -1657,29 +2498,56 @@ uint64_t HSA_API hsa_queue_load_read_index_relaxed(const hsa_queue_t *queue); * * @return Write index of the queue pointed by @p queue. */ -uint64_t HSA_API hsa_queue_load_write_index_acquire(const hsa_queue_t *queue); +uint64_t HSA_API hsa_queue_load_write_index_scacquire( + const hsa_queue_t *queue); /** - * @copydoc hsa_queue_load_write_index_acquire + * @copydoc hsa_queue_load_write_index_scacquire */ -uint64_t HSA_API hsa_queue_load_write_index_relaxed(const hsa_queue_t *queue); +uint64_t HSA_API hsa_queue_load_write_index_relaxed( + const hsa_queue_t *queue); /** * @brief Atomically set the write index of a queue. * + * @details It is recommended that the application uses this function to update + * the write index when there is a single agent submitting work to the queue + * (the queue type is ::HSA_QUEUE_TYPE_SINGLE). + * * @param[in] queue Pointer to a queue. * * @param[in] value Value to assign to the write index. * */ -void HSA_API hsa_queue_store_write_index_relaxed(const hsa_queue_t *queue, - uint64_t value); +void HSA_API hsa_queue_store_write_index_relaxed( + const hsa_queue_t *queue, + uint64_t value); + +/** + * @deprecated Renamed as ::hsa_queue_store_write_index_screlease. + * + * @copydoc hsa_queue_store_write_index_screlease + */ +void HSA_API HSA_DEPRECATED hsa_queue_store_write_index_release( + const hsa_queue_t *queue, + uint64_t value); /** * @copydoc hsa_queue_store_write_index_relaxed */ -void HSA_API hsa_queue_store_write_index_release(const hsa_queue_t *queue, - uint64_t value); +void HSA_API hsa_queue_store_write_index_screlease( + const hsa_queue_t *queue, + uint64_t value); + +/** + * @deprecated Renamed as ::hsa_queue_cas_write_index_scacq_screl. + * + * @copydoc hsa_queue_cas_write_index_scacq_screl + */ +uint64_t HSA_API HSA_DEPRECATED hsa_queue_cas_write_index_acq_rel( + const hsa_queue_t *queue, + uint64_t expected, + uint64_t value); /** * @brief Atomically set the write index of a queue if the observed value is @@ -1695,30 +2563,63 @@ void HSA_API hsa_queue_store_write_index_release(const hsa_queue_t *queue, * * @return Previous value of the write index. */ -uint64_t HSA_API hsa_queue_cas_write_index_acq_rel(const hsa_queue_t *queue, - uint64_t expected, - uint64_t value); +uint64_t HSA_API hsa_queue_cas_write_index_scacq_screl( + const hsa_queue_t *queue, + uint64_t expected, + uint64_t value); /** - * @copydoc hsa_queue_cas_write_index_acq_rel + * @deprecated Renamed as ::hsa_queue_cas_write_index_scacquire. + * + * @copydoc hsa_queue_cas_write_index_scacquire */ -uint64_t HSA_API hsa_queue_cas_write_index_acquire(const hsa_queue_t *queue, - uint64_t expected, - uint64_t value); +uint64_t HSA_API HSA_DEPRECATED hsa_queue_cas_write_index_acquire( + const hsa_queue_t *queue, + uint64_t expected, + uint64_t value); /** - * @copydoc hsa_queue_cas_write_index_acq_rel + * @copydoc hsa_queue_cas_write_index_scacq_screl */ -uint64_t HSA_API hsa_queue_cas_write_index_relaxed(const hsa_queue_t *queue, - uint64_t expected, - uint64_t value); +uint64_t HSA_API hsa_queue_cas_write_index_scacquire( + const hsa_queue_t *queue, + uint64_t expected, + uint64_t value); /** - * @copydoc hsa_queue_cas_write_index_acq_rel + * @copydoc hsa_queue_cas_write_index_scacq_screl */ -uint64_t HSA_API hsa_queue_cas_write_index_release(const hsa_queue_t *queue, - uint64_t expected, - uint64_t value); +uint64_t HSA_API hsa_queue_cas_write_index_relaxed( + const hsa_queue_t *queue, + uint64_t expected, + uint64_t value); + +/** + * @deprecated Renamed as ::hsa_queue_cas_write_index_screlease. + * + * @copydoc hsa_queue_cas_write_index_screlease + */ +uint64_t HSA_API HSA_DEPRECATED hsa_queue_cas_write_index_release( + const hsa_queue_t *queue, + uint64_t expected, + uint64_t value); + +/** + * @copydoc hsa_queue_cas_write_index_scacq_screl + */ +uint64_t HSA_API hsa_queue_cas_write_index_screlease( + const hsa_queue_t *queue, + uint64_t expected, + uint64_t value); + +/** + * @deprecated Renamed as ::hsa_queue_add_write_index_scacq_screl. + * + * @copydoc hsa_queue_add_write_index_scacq_screl + */ +uint64_t HSA_API HSA_DEPRECATED hsa_queue_add_write_index_acq_rel( + const hsa_queue_t *queue, + uint64_t value); /** * @brief Atomically increment the write index of a queue by an offset. @@ -1729,26 +2630,48 @@ uint64_t HSA_API hsa_queue_cas_write_index_release(const hsa_queue_t *queue, * * @return Previous value of the write index. */ -uint64_t HSA_API - hsa_queue_add_write_index_acq_rel(const hsa_queue_t *queue, uint64_t value); +uint64_t HSA_API hsa_queue_add_write_index_scacq_screl( + const hsa_queue_t *queue, + uint64_t value); /** - * @copydoc hsa_queue_add_write_index_acq_rel + * @deprecated Renamed as ::hsa_queue_add_write_index_scacquire. + * + * @copydoc hsa_queue_add_write_index_scacquire */ -uint64_t HSA_API - hsa_queue_add_write_index_acquire(const hsa_queue_t *queue, uint64_t value); +uint64_t HSA_API HSA_DEPRECATED hsa_queue_add_write_index_acquire( + const hsa_queue_t *queue, + uint64_t value); /** - * @copydoc hsa_queue_add_write_index_acq_rel + * @copydoc hsa_queue_add_write_index_scacq_screl */ -uint64_t HSA_API - hsa_queue_add_write_index_relaxed(const hsa_queue_t *queue, uint64_t value); +uint64_t HSA_API hsa_queue_add_write_index_scacquire( + const hsa_queue_t *queue, + uint64_t value); /** - * @copydoc hsa_queue_add_write_index_acq_rel + * @copydoc hsa_queue_add_write_index_scacq_screl */ -uint64_t HSA_API - hsa_queue_add_write_index_release(const hsa_queue_t *queue, uint64_t value); +uint64_t HSA_API hsa_queue_add_write_index_relaxed( + const hsa_queue_t *queue, + uint64_t value); + +/** + * @deprecated Renamed as ::hsa_queue_add_write_index_screlease. + * + * @copydoc hsa_queue_add_write_index_screlease + */ +uint64_t HSA_API HSA_DEPRECATED hsa_queue_add_write_index_release( + const hsa_queue_t *queue, + uint64_t value); + +/** + * @copydoc hsa_queue_add_write_index_scacq_screl + */ +uint64_t HSA_API hsa_queue_add_write_index_screlease( + const hsa_queue_t *queue, + uint64_t value); /** * @brief Atomically set the read index of a queue. @@ -1763,16 +2686,28 @@ uint64_t HSA_API * @param[in] value Value to assign to the read index. * */ -void HSA_API hsa_queue_store_read_index_relaxed(const hsa_queue_t *queue, - uint64_t value); +void HSA_API hsa_queue_store_read_index_relaxed( + const hsa_queue_t *queue, + uint64_t value); + +/** + * @deprecated Renamed as ::hsa_queue_store_read_index_screlease. + * + * @copydoc hsa_queue_store_read_index_screlease + */ +void HSA_API HSA_DEPRECATED hsa_queue_store_read_index_release( + const hsa_queue_t *queue, + uint64_t value); /** * @copydoc hsa_queue_store_read_index_relaxed */ -void HSA_API hsa_queue_store_read_index_release(const hsa_queue_t *queue, - uint64_t value); +void HSA_API hsa_queue_store_read_index_screlease( + const hsa_queue_t *queue, + uint64_t value); /** @} */ + /** \defgroup aql Architected Queuing Language * @{ */ @@ -1842,19 +2777,19 @@ typedef enum { * determined by the corresponding value in ::hsa_packet_header_width_t. The * offset and the width are expressed in bits. */ -typedef enum { + typedef enum { /** * Packet type. The value of this sub-field must be one of * ::hsa_packet_type_t. If the type is ::HSA_PACKET_TYPE_VENDOR_SPECIFIC, the * packet layout is vendor-specific. */ - HSA_PACKET_HEADER_TYPE = 0, + HSA_PACKET_HEADER_TYPE = 0, /** * Barrier bit. If the barrier bit is set, the processing of the current * packet only launches when all preceding packets (within the same queue) are * complete. */ - HSA_PACKET_HEADER_BARRIER = 8, + HSA_PACKET_HEADER_BARRIER = 8, /** * Acquire fence scope. The value of this sub-field determines the scope and * type of the memory fence operation applied before the packet enters the @@ -1864,7 +2799,11 @@ typedef enum { * sees any data previously released at the scopes specified by the acquire * fence. The value of this sub-field must be one of ::hsa_fence_scope_t. */ - HSA_PACKET_HEADER_ACQUIRE_FENCE_SCOPE = 9, + HSA_PACKET_HEADER_SCACQUIRE_FENCE_SCOPE = 9, + /** + * @deprecated Renamed as ::HSA_PACKET_HEADER_SCACQUIRE_FENCE_SCOPE. + */ + HSA_PACKET_HEADER_ACQUIRE_FENCE_SCOPE = 9, /** * Release fence scope, The value of this sub-field determines the scope and * type of the memory fence operation applied after kernel completion but @@ -1874,18 +2813,30 @@ typedef enum { * kernel agent visible in all the scopes specified by the release fence. The * value of this sub-field must be one of ::hsa_fence_scope_t. */ - HSA_PACKET_HEADER_RELEASE_FENCE_SCOPE = 11 -} hsa_packet_header_t; + HSA_PACKET_HEADER_SCRELEASE_FENCE_SCOPE = 11, + /** + * @deprecated Renamed as ::HSA_PACKET_HEADER_SCRELEASE_FENCE_SCOPE. + */ + HSA_PACKET_HEADER_RELEASE_FENCE_SCOPE = 11 + } hsa_packet_header_t; /** * @brief Width (in bits) of the sub-fields in ::hsa_packet_header_t. */ -typedef enum { - HSA_PACKET_HEADER_WIDTH_TYPE = 8, - HSA_PACKET_HEADER_WIDTH_BARRIER = 1, - HSA_PACKET_HEADER_WIDTH_ACQUIRE_FENCE_SCOPE = 2, - HSA_PACKET_HEADER_WIDTH_RELEASE_FENCE_SCOPE = 2 -} hsa_packet_header_width_t; + typedef enum { + HSA_PACKET_HEADER_WIDTH_TYPE = 8, + HSA_PACKET_HEADER_WIDTH_BARRIER = 1, + HSA_PACKET_HEADER_WIDTH_SCACQUIRE_FENCE_SCOPE = 2, + /** + * @deprecated Use HSA_PACKET_HEADER_WIDTH_SCACQUIRE_FENCE_SCOPE. + */ + HSA_PACKET_HEADER_WIDTH_ACQUIRE_FENCE_SCOPE = 2, + HSA_PACKET_HEADER_WIDTH_SCRELEASE_FENCE_SCOPE = 2, + /** + * @deprecated Use HSA_PACKET_HEADER_WIDTH_SCRELEASE_FENCE_SCOPE. + */ + HSA_PACKET_HEADER_WIDTH_RELEASE_FENCE_SCOPE = 2 + } hsa_packet_header_width_t; /** * @brief Sub-fields of the kernel dispatch packet @a setup field. The offset @@ -1894,21 +2845,21 @@ typedef enum { * corresponding value in ::hsa_kernel_dispatch_packet_setup_width_t. The * offset and the width are expressed in bits. */ -typedef enum { + typedef enum { /** * Number of dimensions of the grid. Valid values are 1, 2, or 3. * */ - HSA_KERNEL_DISPATCH_PACKET_SETUP_DIMENSIONS = 0 -} hsa_kernel_dispatch_packet_setup_t; + HSA_KERNEL_DISPATCH_PACKET_SETUP_DIMENSIONS = 0 + } hsa_kernel_dispatch_packet_setup_t; /** * @brief Width (in bits) of the sub-fields in * ::hsa_kernel_dispatch_packet_setup_t. */ -typedef enum { - HSA_KERNEL_DISPATCH_PACKET_SETUP_WIDTH_DIMENSIONS = 2 -} hsa_kernel_dispatch_packet_setup_width_t; + typedef enum { + HSA_KERNEL_DISPATCH_PACKET_SETUP_WIDTH_DIMENSIONS = 2 + } hsa_kernel_dispatch_packet_setup_width_t; /** * @brief AQL kernel dispatch packet @@ -1989,7 +2940,7 @@ typedef struct hsa_kernel_dispatch_packet_s { uint64_t kernel_object; #ifdef HSA_LARGE_MODEL - void *kernarg_address; + void* kernarg_address; #elif defined HSA_LITTLE_ENDIAN /** * Pointer to a buffer containing the kernel arguments. May be NULL. @@ -1998,14 +2949,14 @@ typedef struct hsa_kernel_dispatch_packet_s { * modified once the kernel dispatch packet is enqueued until the dispatch has * completed execution. */ - void *kernarg_address; + void* kernarg_address; /** * Reserved. Must be 0. */ uint32_t reserved1; #else uint32_t reserved1; - void *kernarg_address; + void* kernarg_address; #endif /** @@ -2042,19 +2993,19 @@ typedef struct hsa_agent_dispatch_packet_s { uint32_t reserved0; #ifdef HSA_LARGE_MODEL - void *return_address; + void* return_address; #elif defined HSA_LITTLE_ENDIAN /** * Address where to store the function return values, if any. */ - void *return_address; + void* return_address; /** * Reserved. Must be 0. */ uint32_t reserved1; #else uint32_t reserved1; - void *return_address; + void* return_address; #endif /** @@ -2181,8 +3132,12 @@ typedef enum { /** * Group segment. Used to hold data that is shared by the work-items of a * work-group. - */ - HSA_REGION_SEGMENT_GROUP = 3 + */ + HSA_REGION_SEGMENT_GROUP = 3, + /** + * Kernarg segment. Used to store kernel arguments. + */ + HSA_REGION_SEGMENT_KERNARG = 4 } hsa_region_segment_t; /** @@ -2235,13 +3190,22 @@ typedef enum { * of ::HSA_REGION_INFO_SIZE. The type of this attribute is size_t. * * If the region is in the global or readonly segments, this is the maximum - * size that the application can pass to ::hsa_memory_allocate. If the region - * is in the group segment, this is the maximum size (per work-group) that can - * be requested for a given kernel dispatch. If the region is in the private - * segment, this is the maximum size (per work-item) that can be request for a - * specific kernel dispatch. + * size that the application can pass to ::hsa_memory_allocate. + * + * If the region is in the group segment, this is the maximum size (per + * work-group) that can be requested for a given kernel dispatch. If the + * region is in the private segment, this is the maximum size (per work-item) + * that can be requested for a specific kernel dispatch, and must be at least + * 256 bytes. */ HSA_REGION_INFO_ALLOC_MAX_SIZE = 4, + /** + * Maximum size (per work-group) of private memory that can be requested for a + * specific kernel dispatch. Must be at least 65536 bytes. The type of this + * attribute is uint32_t. The value of this attribute is undefined if the + * region is not in the private segment. + */ + HSA_REGION_INFO_ALLOC_MAX_PRIVATE_WORKGROUP_SIZE = 8, /** * Indicates whether memory in this region can be allocated using * ::hsa_memory_allocate. The type of this attribute is bool. @@ -2261,8 +3225,8 @@ typedef enum { /** * Alignment of buffers allocated by ::hsa_memory_allocate in this region. The * value of this attribute is only defined if - * ::HSA_REGION_INFO_RUNTIME_ALLOC_ALLOWED is true for this region, and must - * be a power of 2. The type of this attribute is size_t. + * ::HSA_REGION_INFO_RUNTIME_ALLOC_ALLOWED is true for this region, and must be + * a power of 2. The type of this attribute is size_t. */ HSA_REGION_INFO_RUNTIME_ALLOC_ALIGNMENT = 7 } hsa_region_info_t; @@ -2288,9 +3252,10 @@ typedef enum { * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p attribute is an invalid * region attribute, or @p value is NULL. */ -hsa_status_t HSA_API hsa_region_get_info(hsa_region_t region, - hsa_region_info_t attribute, - void *value); +hsa_status_t HSA_API hsa_region_get_info( + hsa_region_t region, + hsa_region_info_t attribute, + void* value); /** * @brief Iterate over the memory regions associated with a given agent, and @@ -2318,7 +3283,8 @@ hsa_status_t HSA_API hsa_region_get_info(hsa_region_t region, */ hsa_status_t HSA_API hsa_agent_iterate_regions( hsa_agent_t agent, - hsa_status_t (*callback)(hsa_region_t region, void *data), void *data); + hsa_status_t (*callback)(hsa_region_t region, void* data), + void* data); /** * @brief Allocate a block of memory in a given region. @@ -2340,7 +3306,8 @@ hsa_status_t HSA_API hsa_agent_iterate_regions( * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been * initialized. * - * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES No memory is available. + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to allocate + * the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_REGION The region is invalid. * @@ -2350,8 +3317,9 @@ hsa_status_t HSA_API hsa_agent_iterate_regions( * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p ptr is NULL, or @p size is 0. */ -hsa_status_t HSA_API - hsa_memory_allocate(hsa_region_t region, size_t size, void **ptr); +hsa_status_t HSA_API hsa_memory_allocate(hsa_region_t region, + size_t size, + void** ptr); /** * @brief Deallocate a block of memory previously allocated using @@ -2365,14 +3333,20 @@ hsa_status_t HSA_API * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been * initialized. */ -hsa_status_t HSA_API hsa_memory_free(void *ptr); +hsa_status_t HSA_API hsa_memory_free(void* ptr); /** - * @brief Copy a block of memory. + * @brief Copy a block of memory from the location pointed to by @p src to the + * memory block pointed to by @p dst. * - * @param[out] dst Buffer where the content is to be copied. + * @param[out] dst Buffer where the content is to be copied. If @p dst is in + * coarse-grained memory, the copied data is only visible to the agent currently + * assigned (::hsa_memory_assign_agent) to @p dst. * - * @param[in] src A valid pointer to the source of data to be copied. + * @param[in] src A valid pointer to the source of data to be copied. The source + * buffer must not overlap with the destination buffer. If the source buffer is + * in coarse-grained memory then it must be assigned to an agent, from which the + * data will be retrieved. * * @param[in] size Number of bytes to copy. If @p size is 0, no copy is * performed and the function returns success. Copying a number of bytes larger @@ -2387,7 +3361,10 @@ hsa_status_t HSA_API hsa_memory_free(void *ptr); * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT The source or destination * pointers are NULL. */ -hsa_status_t HSA_API hsa_memory_copy(void *dst, const void *src, size_t size); +hsa_status_t HSA_API hsa_memory_copy( + void *dst, + const void *src, + size_t size); /** * @brief Change the ownership of a global, coarse-grained buffer. @@ -2403,7 +3380,7 @@ hsa_status_t HSA_API hsa_memory_copy(void *dst, const void *src, size_t size); * behavior. The virtual location (address) of the passed buffer is never * modified. * - * @param[in] ptr Base address of a global buffer. The pointer should match an + * @param[in] ptr Base address of a global buffer. The pointer must match an * address previously returned by ::hsa_memory_allocate. The size of the buffer * affected by the ownership change is identical to the size of that previous * allocation. If @p ptr points to a fine-grained global buffer, no operation is @@ -2425,14 +3402,16 @@ hsa_status_t HSA_API hsa_memory_copy(void *dst, const void *src, size_t size); * * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid. * - * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime is unable to - * acquire the resources required by the operation. + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to allocate + * the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p ptr is NULL, or @p access is * not a valid access value. */ -hsa_status_t HSA_API hsa_memory_assign_agent(void *ptr, hsa_agent_t agent, - hsa_access_permission_t access); +hsa_status_t HSA_API hsa_memory_assign_agent( + void *ptr, + hsa_agent_t agent, + hsa_access_permission_t access); /** * @@ -2446,12 +3425,15 @@ hsa_status_t HSA_API hsa_memory_assign_agent(void *ptr, hsa_agent_t agent, * * Registration is only recommended for buffers in the global segment that have * not been allocated using the HSA allocator (::hsa_memory_allocate), but an OS - * allocator instead. + * allocator instead. Registering an OS-allocated buffer in the base profile is + * equivalent to a no-op. * * Registrations should not overlap. * - * @param[in] ptr A buffer in global memory. If a NULL pointer is passed, no - * operation is performed. + * @param[in] ptr A buffer in global, fine-grained memory. If a NULL pointer is + * passed, no operation is performed. If the buffer has been allocated using + * ::hsa_memory_allocate, or has already been registered, no operation is + * performed. * * @param[in] size Requested registration size in bytes. A size of 0 is * only allowed if @p ptr is NULL. @@ -2461,13 +3443,15 @@ hsa_status_t HSA_API hsa_memory_assign_agent(void *ptr, hsa_agent_t agent, * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been * initialized. * - * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES There is a failure in - * allocating the necessary resources. + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to allocate + * the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p size is 0 but @p ptr * is not NULL. */ -hsa_status_t HSA_API hsa_memory_register(void *ptr, size_t size); +hsa_status_t HSA_API hsa_memory_register( + void *ptr, + size_t size); /** * @@ -2487,77 +3471,14 @@ hsa_status_t HSA_API hsa_memory_register(void *ptr, size_t size); * initialized. * */ -hsa_status_t HSA_API hsa_memory_deregister(void *ptr, size_t size); +hsa_status_t HSA_API hsa_memory_deregister( + void *ptr, + size_t size); /** @} */ -/** \defgroup symbol-attributes Symbol Attributes - * @{ - */ -/** - * @brief Symbol type. - */ -typedef enum { - /** - * Variable. - */ - HSA_SYMBOL_KIND_VARIABLE = 0, - /** - * Kernel. - */ - HSA_SYMBOL_KIND_KERNEL = 1, - /** - * Indirect function. - */ - HSA_SYMBOL_KIND_INDIRECT_FUNCTION = 2 -} hsa_symbol_kind_t; - -/** - * @brief Allocation type of a variable. - */ -typedef enum { - /** - * Agent allocation. - */ - HSA_VARIABLE_ALLOCATION_AGENT = 0, - /** - * Program allocation. - */ - HSA_VARIABLE_ALLOCATION_PROGRAM = 1 -} hsa_variable_allocation_t; - -/** - * @brief Linkage type of a symbol. - */ -typedef enum { - /** - * Module linkage. - */ - HSA_SYMBOL_LINKAGE_MODULE = 0, - /** - * Program linkage. - */ - HSA_SYMBOL_LINKAGE_PROGRAM = 1 -} hsa_symbol_linkage_t; - -/** - * @brief Memory segment associated with a variable. - */ -typedef enum { - /** - * Global memory segment. - */ - HSA_VARIABLE_SEGMENT_GLOBAL = 0, - /** - * Readonly memory segment. - */ - HSA_VARIABLE_SEGMENT_READONLY = 1 -} hsa_variable_segment_t; - -/** @} */ - -/** \defgroup code-object Code Object +/** \defgroup instruction-set-architecture Instruction Set Architecture. * @{ */ @@ -2566,38 +3487,80 @@ typedef enum { */ typedef struct hsa_isa_s { /** - * Opaque handle. + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. */ uint64_t handle; } hsa_isa_t; /** - * @brief Retrieve a reference to an ISA handle out of a symbolic name. + * @brief Retrieve a reference to an instruction set architecture handle out of + * a symbolic name. * - * @param[in] name Vendor-specific name associated with a particular instruction - * set architecture. Must be a NUL-terminated string. + * @param[in] name Vendor-specific name associated with a a particular + * instruction set architecture. @p name must start with the vendor name and a + * colon (for example, "AMD:"). The rest of the name is vendor-specific. Must be + * a NUL-terminated string. * * @param[out] isa Memory location where the HSA runtime stores the ISA handle * corresponding to the given name. Must not be NULL. * * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. * - * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p name is NULL, or @p isa is - * NULL. + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. * * @retval ::HSA_STATUS_ERROR_INVALID_ISA_NAME The given name does not * correspond to any instruction set architecture. + * + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p name is NULL, or @p isa is + * NULL. */ hsa_status_t HSA_API hsa_isa_from_name( - const char* name, - hsa_isa_t* isa); + const char *name, + hsa_isa_t *isa); + +/** + * @brief Iterate over the instruction sets supported by the given agent, and + * invoke an application-defined callback on every iteration. The iterator is + * deterministic: if an agent supports several instruction set architectures, + * they are traversed in the same order in every invocation of this function. + * + * @param[in] agent A valid agent. + * + * @param[in] callback Callback to be invoked once per instruction set + * architecture. The HSA runtime passes two arguments to the callback: the + * ISA and the application data. If @p callback returns a status other than + * ::HSA_STATUS_SUCCESS for a particular iteration, the traversal stops and + * that status value is returned. + * + * @param[in] data Application data that is passed to @p callback on every + * iteration. May be NULL. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL. + */ +hsa_status_t HSA_API hsa_agent_iterate_isas( + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_isa_t isa, void *data), + void *data); /** * @brief Instruction set architecture attributes. */ typedef enum { /** - * The length of the ISA name. The type of this attribute is uint32_t. + * The length of the ISA name in bytes, not including the NUL terminator. The + * type of this attribute is uint32_t. */ HSA_ISA_INFO_NAME_LENGTH = 0, /** @@ -2606,25 +3569,109 @@ typedef enum { */ HSA_ISA_INFO_NAME = 1, /** + * @deprecated + * * Number of call conventions supported by the instruction set architecture. - * The type of this attribute is uint32_t. + * Must be greater than zero. The type of this attribute is uint32_t. */ HSA_ISA_INFO_CALL_CONVENTION_COUNT = 2, /** + * @deprecated + * * Number of work-items in a wavefront for a given call convention. Must be a * power of 2 in the range [1,256]. The type of this attribute is uint32_t. */ HSA_ISA_INFO_CALL_CONVENTION_INFO_WAVEFRONT_SIZE = 3, /** + * @deprecated + * * Number of wavefronts per compute unit for a given call convention. In * practice, other factors (for example, the amount of group memory used by a * work-group) may further limit the number of wavefronts per compute * unit. The type of this attribute is uint32_t. */ - HSA_ISA_INFO_CALL_CONVENTION_INFO_WAVEFRONTS_PER_COMPUTE_UNIT = 4 + HSA_ISA_INFO_CALL_CONVENTION_INFO_WAVEFRONTS_PER_COMPUTE_UNIT = 4, + /** + * Machine models supported by the instruction set architecture. The type of + * this attribute is a bool[2]. If the ISA supports the small machine model, + * the element at index ::HSA_MACHINE_MODEL_SMALL is true. If the ISA supports + * the large model, the element at index ::HSA_MACHINE_MODEL_LARGE is true. + */ + HSA_ISA_INFO_MACHINE_MODELS = 5, + /** + * Profiles supported by the instruction set architecture. The type of this + * attribute is a bool[2]. If the ISA supports the base profile, the element + * at index ::HSA_PROFILE_BASE is true. If the ISA supports the full profile, + * the element at index ::HSA_PROFILE_FULL is true. + */ + HSA_ISA_INFO_PROFILES = 6, + /** + * Default floating-point rounding modes supported by the instruction set + * architecture. The type of this attribute is a bool[3]. The value at a given + * index is true if the corresponding rounding mode in + * ::hsa_default_float_rounding_mode_t is supported. At least one default mode + * has to be supported. + * + * If the default mode is supported, then + * ::HSA_ISA_INFO_BASE_PROFILE_DEFAULT_FLOAT_ROUNDING_MODES must report that + * both the zero and the near roundings modes are supported. + */ + HSA_ISA_INFO_DEFAULT_FLOAT_ROUNDING_MODES = 7, + /** + * Default floating-point rounding modes supported by the instruction set + * architecture in the Base profile. The type of this attribute is a + * bool[3]. The value at a given index is true if the corresponding rounding + * mode in ::hsa_default_float_rounding_mode_t is supported. The value at + * index HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT must be false. At least one + * of the values at indexes ::HSA_DEFAULT_FLOAT_ROUNDING_MODE_ZERO or + * HSA_DEFAULT_FLOAT_ROUNDING_MODE_NEAR must be true. + */ + HSA_ISA_INFO_BASE_PROFILE_DEFAULT_FLOAT_ROUNDING_MODES = 8, + /** + * Flag indicating that the f16 HSAIL operation is at least as fast as the + * f32 operation in the instruction set architecture. The type of this + * attribute is bool. + */ + HSA_ISA_INFO_FAST_F16_OPERATION = 9, + /** + * 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_ISA_INFO_WORKGROUP_MAX_SIZE. The type of this attribute is + * uint16_t[3]. + */ + HSA_ISA_INFO_WORKGROUP_MAX_DIM = 12, + /** + * Maximum total number of work-items in a work-group. The type + * of this attribute is uint32_t. + */ + HSA_ISA_INFO_WORKGROUP_MAX_SIZE = 13, + /** + * 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_ISA_INFO_WORKGROUP_MAX_DIM. No maximum can exceed the value of + * ::HSA_ISA_INFO_GRID_MAX_SIZE. The type of this attribute is + * ::hsa_dim3_t. + */ + HSA_ISA_INFO_GRID_MAX_DIM = 14, + /** + * Maximum total number of work-items in a grid. The type of this + * attribute is uint64_t. + */ + HSA_ISA_INFO_GRID_MAX_SIZE = 16, + /** + * Maximum number of fbarriers per work-group. Must be at least 32. The + * type of this attribute is uint32_t. + */ + HSA_ISA_INFO_FBARRIER_MAX_SIZE = 17 } hsa_isa_info_t; /** + * @deprecated The concept of call convention has been deprecated. If the + * application wants to query the value of an attribute for a given instruction + * set architecture, use ::hsa_isa_get_info_alt instead. If the application + * wants to query an attribute that is specific to a given combination of ISA + * and wavefront, use ::hsa_wavefront_get_info. + * * @brief Get the current value of an attribute for a given instruction set * architecture (ISA). * @@ -2649,18 +3696,235 @@ typedef enum { * @retval ::HSA_STATUS_ERROR_INVALID_ISA The instruction set architecture is * invalid. * - * @retval ::HSA_STATUS_ERROR_INVALID_INDEX @p index out of range. + * @retval ::HSA_STATUS_ERROR_INVALID_INDEX The index is out of range. * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p attribute is an invalid - * instruction set architecture attribute, or @p value is NULL. + * instruction set architecture attribute, or @p value is + * NULL. */ -hsa_status_t HSA_API hsa_isa_get_info( +hsa_status_t HSA_API HSA_DEPRECATED hsa_isa_get_info( hsa_isa_t isa, hsa_isa_info_t attribute, uint32_t index, - void* value); + void *value); /** + * @brief Get the current value of an attribute for a given instruction set + * architecture (ISA). + * + * @param[in] isa A valid instruction set architecture. + * + * @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_ISA The instruction set architecture is + * invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p attribute is an invalid + * instruction set architecture attribute, or @p value is + * NULL. + */ +hsa_status_t HSA_API hsa_isa_get_info_alt( + hsa_isa_t isa, + hsa_isa_info_t attribute, + void *value); + +/** + * @brief Retrieve the exception policy support for a given combination of + * instruction set architecture and profile. + * + * @param[in] isa A valid instruction set architecture. + * + * @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_ISA The instruction set architecture 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_isa_get_exception_policies( + hsa_isa_t isa, + hsa_profile_t profile, + uint16_t *mask); + +/** + * @brief Floating-point types. + */ +typedef enum { + /** + * 16-bit floating-point type. + */ + HSA_FP_TYPE_16 = 1, + /** + * 32-bit floating-point type. + */ + HSA_FP_TYPE_32 = 2, + /** + * 64-bit floating-point type. + */ + HSA_FP_TYPE_64 = 4 +} hsa_fp_type_t; + +/** + * @brief Flush to zero modes. + */ +typedef enum { + /** + * Flush to zero. + */ + HSA_FLUSH_MODE_FTZ = 1, + /** + * Do not flush to zero. + */ + HSA_FLUSH_MODE_NON_FTZ = 2 +} hsa_flush_mode_t; + +/** + * @brief Round methods. + */ +typedef enum { + /** + * Single round method. + */ + HSA_ROUND_METHOD_SINGLE = 1, + /** + * Double round method. + */ + HSA_ROUND_METHOD_DOUBLE = 2 +} hsa_round_method_t; + +/** + * @brief Retrieve the round method (single or double) used to implement the + * floating-point multiply add instruction (mad) for a given combination of + * instruction set architecture, floating-point type, and flush to zero + * modifier. + * + * @param[in] isa Instruction set architecture. + * + * @param[in] fp_type Floating-point type. + * + * @param[in] flush_mode Flush to zero modifier. + * + * @param[out] round_method Pointer to a memory location where the HSA + * runtime stores the round method used by the implementation. 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_ISA The instruction set architecture is + * invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p fp_type is not a valid + * floating-point type, or @p flush_mode is not a valid flush to zero modifier, + * or @p round_method is NULL. + */ +hsa_status_t HSA_API hsa_isa_get_round_method( + hsa_isa_t isa, + hsa_fp_type_t fp_type, + hsa_flush_mode_t flush_mode, + hsa_round_method_t *round_method); + +/** + * @brief Wavefront handle + */ +typedef struct hsa_wavefront_s { + /** + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. + */ + uint64_t handle; +} hsa_wavefront_t; + +/** + * @brief Wavefront attributes. + */ +typedef enum { + /** + * Number of work-items in the wavefront. Must be a power of 2 in the range + * [1,256]. The type of this attribute is uint32_t. + */ + HSA_WAVEFRONT_INFO_SIZE = 0 +} hsa_wavefront_info_t; + +/** + * @brief Get the current value of a wavefront attribute. + * + * @param[in] wavefront A wavefront. + * + * @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_WAVEFRONT The wavefront is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p attribute is an invalid + * wavefront attribute, or @p value is NULL. + */ +hsa_status_t HSA_API hsa_wavefront_get_info( + hsa_wavefront_t wavefront, + hsa_wavefront_info_t attribute, + void *value); + +/** + * @brief Iterate over the different wavefronts supported by an instruction set + * architecture, and invoke an application-defined callback on every iteration. + * + * @param[in] isa Instruction set architecture. + * + * @param[in] callback Callback to be invoked once per wavefront that is + * supported by the agent. The HSA runtime passes two arguments to the callback: + * the wavefront handle and the application data. If @p callback returns a + * status other than ::HSA_STATUS_SUCCESS for a particular iteration, the + * traversal stops and that value is returned. + * + * @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_ISA The instruction set architecture is + * invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL. + */ +hsa_status_t HSA_API hsa_isa_iterate_wavefronts( + hsa_isa_t isa, + hsa_status_t (*callback)(hsa_wavefront_t wavefront, void *data), + void *data); + +/** + * @deprecated Use ::hsa_agent_iterate_isas to query which instructions set + * architectures are supported by a given agent. + * * @brief Check if the instruction set architecture of a code object can be * executed on an agent associated with another architecture. * @@ -2675,441 +3939,127 @@ hsa_status_t HSA_API hsa_isa_get_info( * * @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_ISA @p code_object_isa or @p agent_isa are * invalid. * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p result is NULL. */ -hsa_status_t HSA_API hsa_isa_compatible( +hsa_status_t HSA_API HSA_DEPRECATED hsa_isa_compatible( hsa_isa_t code_object_isa, hsa_isa_t agent_isa, - bool* result); - -/** - * @brief An opaque handle to a code object, which contains ISA for finalized - * kernels and indirect functions together with information about the - * global/readonly segment variables they reference. - */ -typedef struct hsa_code_object_s { - /** - * Opaque handle. - */ - uint64_t handle; -} hsa_code_object_t; - -/** - * @brief Opaque handle to application data that is passed to the serialization - * and deserialization functions. - */ -typedef struct hsa_callback_data_s { - /** - * Opaque handle. - */ - uint64_t handle; -} hsa_callback_data_t; - -/** - * @brief Serialize a code object. Can be used for offline finalization, - * install-time finalization, disk code caching, etc. - * - * @param[in] code_object Code object. - * - * @param[in] alloc_callback Callback function for memory allocation. Must not - * be NULL. The HSA runtime passes three arguments to the callback: the - * allocation size, the application data, and a pointer to a memory location - * where the application stores the allocation result. The HSA runtime invokes - * @p alloc_callback once to allocate a buffer that contains the serialized - * version of @p code_object. If the callback returns a status code other than - * ::HSA_STATUS_SUCCESS, this function returns the same code. - * - * @param[in] callback_data Application data that is passed to @p - * alloc_callback. May be NULL. - * - * @param[in] options Vendor-specific options. May be NULL. - * - * @param[out] serialized_code_object Memory location where the HSA runtime - * stores a pointer to the serialized code object. Must not be NULL. - * - * @param[out] serialized_code_object_size Memory location where the HSA runtime - * stores the size (in bytes) of @p serialized_code_object. The returned value - * matches the allocation size passed by the HSA runtime to @p - * alloc_callback. Must not be NULL. - * - * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. - * - * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been - * initialized. - * - * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES There is a failure to allocate - * resources required for the operation. - * - * @retval ::HSA_STATUS_ERROR_INVALID_CODE_OBJECT @p code_object is invalid. - * - * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p alloc_callback, @p - * serialized_code_object, or @p serialized_code_object_size are NULL. - */ -hsa_status_t HSA_API hsa_code_object_serialize( - hsa_code_object_t code_object, - hsa_status_t (*alloc_callback)(size_t size, hsa_callback_data_t data, void **address), - hsa_callback_data_t callback_data, - const char *options, - void **serialized_code_object, - size_t *serialized_code_object_size); - -/** - * @brief Deserialize a code object. - * - * @param[in] serialized_code_object A serialized code object. Must not be NULL. - * - * @param[in] serialized_code_object_size The size (in bytes) of @p - * serialized_code_object. Must not be 0. - * - * @param[in] options Vendor-specific options. May be NULL. - * - * @param[out] code_object Memory location where the HSA runtime stores the - * deserialized code object. - * - * @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 a failure to allocate - * resources required for the operation. - * - * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p serialized_code_object, or @p - * code_object are NULL. @p serialized_code_object_size is 0. - */ -hsa_status_t HSA_API hsa_code_object_deserialize( - void *serialized_code_object, - size_t serialized_code_object_size, - const char *options, - hsa_code_object_t *code_object); - -/** - * @brief Destroy a code object. - * - * @details The lifetime of a code object must exceed that of any executable - * where it has been loaded. If an executable that loaded @p code_object has not - * been destroyed, the behavior is undefined. - * - * @param[in] code_object Code object. The handle becomes invalid after it has - * been destroyed. - * - * @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_CODE_OBJECT @p code_object is invalid. - */ -hsa_status_t HSA_API hsa_code_object_destroy( - hsa_code_object_t code_object); - -/** - * @brief Code object type. - */ -typedef enum { - /** - * Produces code object that contains ISA for all kernels and indirect - * functions in HSA source. - */ - HSA_CODE_OBJECT_TYPE_PROGRAM = 0 -} hsa_code_object_type_t; - -/** - * @brief Code object attributes. - */ -typedef enum { - /** - * The version of the code object. The type of this attribute is a - * NUL-terminated char[64]. If the version of the code object uses less than - * 63 characters, the rest of the array must be filled with NULs. - */ - HSA_CODE_OBJECT_INFO_VERSION = 0, - /** - * Type of code object. The type of this attribute is - * ::hsa_code_object_type_t. - */ - HSA_CODE_OBJECT_INFO_TYPE = 1, - /** - * Instruction set architecture this code object is produced for. The type of - * this attribute is ::hsa_isa_t. - */ - HSA_CODE_OBJECT_INFO_ISA = 2, - /** - * Machine model this code object is produced for. The type of this attribute - * is ::hsa_machine_model_t. - */ - HSA_CODE_OBJECT_INFO_MACHINE_MODEL = 3, - /** - * Profile this code object is produced for. The type of this attribute is - * ::hsa_profile_t. - */ - HSA_CODE_OBJECT_INFO_PROFILE = 4, - /** - * Default floating-point rounding mode used when the code object is - * produced. The type of this attribute is - * ::hsa_default_float_rounding_mode_t. - */ - HSA_CODE_OBJECT_INFO_DEFAULT_FLOAT_ROUNDING_MODE = 5 -} hsa_code_object_info_t; - -/** - * @brief Get the current value of an attribute for a given code object. - * - * @param[in] code_object Code object. - * - * @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 - * code object attribute, or @p value is NULL. - * - * @retval ::HSA_STATUS_ERROR_INVALID_CODE_OBJECT @p code_object is invalid. - */ -hsa_status_t HSA_API hsa_code_object_get_info( - hsa_code_object_t code_object, - hsa_code_object_info_t attribute, - void *value); - -/** - * @brief Code object symbol. - */ -typedef struct hsa_code_symbol_s { - /** - * Opaque handle. - */ - uint64_t handle; -} hsa_code_symbol_t; - -/** - * @brief Get the symbol handle within a code object for a given a symbol name. - * - * @param[in] code_object Code object. - * - * @param[in] symbol_name Symbol name. - * - * @param[out] symbol Memory location where the HSA runtime stores the symbol - * 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_INVALID_CODE_OBJECT @p code_object is invalid. - * - * @retval ::HSA_STATUS_ERROR_INVALID_SYMBOL_NAME There is no symbol with a name - * that matches @p symbol_name. - * - * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p symbol_name is NULL, or - * @p symbol is NULL. - */ -hsa_status_t HSA_API hsa_code_object_get_symbol( - hsa_code_object_t code_object, - const char *symbol_name, - hsa_code_symbol_t *symbol); - -/** - * @brief Code object symbol attributes. - */ -typedef enum { - /** - * The type of the symbol. The type of this attribute is ::hsa_symbol_kind_t. - */ - HSA_CODE_SYMBOL_INFO_TYPE = 0, - /** - * The length of the symbol name. The type of this attribute is uint32_t. - */ - HSA_CODE_SYMBOL_INFO_NAME_LENGTH = 1, - /** - * The name of the symbol. The type of this attribute is character array with - * the length equal to the value of ::HSA_CODE_SYMBOL_INFO_NAME_LENGTH - * attribute - */ - HSA_CODE_SYMBOL_INFO_NAME = 2, - /** - * The length of the module name to which this symbol belongs if this symbol - * has module linkage, otherwise 0 is returned. The type of this attribute is - * uint32_t. - */ - HSA_CODE_SYMBOL_INFO_MODULE_NAME_LENGTH = 3, - /** - * The module name to which this symbol belongs if this symbol has module - * linkage, otherwise empty string is returned. The type of this attribute is - * character array with the length equal to the value of - * ::HSA_CODE_SYMBOL_INFO_MODULE_NAME_LENGTH attribute. - */ - HSA_CODE_SYMBOL_INFO_MODULE_NAME = 4, - /** - * The linkage kind of the symbol. The type of this attribute is - * ::hsa_symbol_linkage_t. - */ - HSA_CODE_SYMBOL_INFO_LINKAGE = 5, - /** - * Indicates whether the symbol corresponds to a definition. The type of this - * attribute is bool. - */ - HSA_CODE_SYMBOL_INFO_IS_DEFINITION = 17, - /** - * The allocation kind of the variable. The value of this attribute is - * undefined if the symbol is not a variable. The type of this attribute is - * ::hsa_variable_allocation_t. - */ - HSA_CODE_SYMBOL_INFO_VARIABLE_ALLOCATION = 6, - /** - * The segment kind of the variable. The value of this attribute is - * undefined if the symbol is not a variable. The type of this attribute is - * ::hsa_variable_segment_t. - */ - HSA_CODE_SYMBOL_INFO_VARIABLE_SEGMENT = 7, - /** - * Alignment of the variable. The value of this attribute is undefined if the - * symbol is not a variable. The type of this attribute is uint32_t. - */ - HSA_CODE_SYMBOL_INFO_VARIABLE_ALIGNMENT = 8, - /** - * Size of the variable. The value of this attribute is undefined if the - * symbol is not a variable. The type of this attribute is uint32_t. - * - * A size of 0 is returned if the variable is an external variable and has an - * unknown dimension. - */ - HSA_CODE_SYMBOL_INFO_VARIABLE_SIZE = 9, - /** - * Indicates whether the variable is constant. The value of this attribute is - * undefined if the symbol is not a variable. The type of this attribute is - * bool. - */ - HSA_CODE_SYMBOL_INFO_VARIABLE_IS_CONST = 10, - /** - * Size of kernarg segment memory that is required to hold the values of the - * kernel arguments, in bytes. The value of this attribute is undefined if the - * symbol is not a kernel. The type of this attribute is uint32_t. - */ - HSA_CODE_SYMBOL_INFO_KERNEL_KERNARG_SEGMENT_SIZE = 11, - /** - * Alignment (in bytes) of the buffer used to pass arguments to the kernel, - * which is the maximum of 16 and the maximum alignment of any of the kernel - * arguments. The value of this attribute is undefined if the symbol is not a - * kernel. The type of this attribute is uint32_t. - */ - HSA_CODE_SYMBOL_INFO_KERNEL_KERNARG_SEGMENT_ALIGNMENT = 12, - /** - * Size of static group segment memory required by the kernel (per - * work-group), in bytes. The value of this attribute is undefined - * if the symbol is not a kernel. The type of this attribute is uint32_t. - * - * The reported amount does not include any dynamically allocated group - * segment memory that may be requested by the application when a kernel is - * dispatched. - */ - HSA_CODE_SYMBOL_INFO_KERNEL_GROUP_SEGMENT_SIZE = 13, - /** - * Size of static private, spill, and arg segment memory required by - * this kernel (per work-item), in bytes. The value of this attribute is - * undefined if the symbol is not a kernel. The type of this attribute is - * uint32_t. - * - * If the value of ::HSA_CODE_SYMBOL_INFO_KERNEL_DYNAMIC_CALLSTACK is true, - * the kernel may use more private memory than the reported value, and the - * application must add the dynamic call stack usage to @a - * private_segment_size when populating a kernel dispatch packet. - */ - HSA_CODE_SYMBOL_INFO_KERNEL_PRIVATE_SEGMENT_SIZE = 14, - /** - * Dynamic callstack flag. The value of this attribute is undefined if the - * symbol is not a kernel. The type of this attribute is bool. - * - * If this flag is set (the value is true), the kernel uses a dynamically - * sized call stack. This can happen if recursive calls, calls to indirect - * functions, or the HSAIL alloca instruction are present in the kernel. - */ - HSA_CODE_SYMBOL_INFO_KERNEL_DYNAMIC_CALLSTACK = 15, - /** - * Call convention of the indirect function. The value of this attribute is - * undefined if the symbol is not an indirect function. The type of this - * attribute is uint32_t. - */ - HSA_CODE_SYMBOL_INFO_INDIRECT_FUNCTION_CALL_CONVENTION = 16 -} hsa_code_symbol_info_t; - -/** - * @brief Get the current value of an attribute for a given code symbol. - * - * @param[in] code_symbol Code symbol. - * - * @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 - * code symbol attribute, or @p value is NULL. - */ -hsa_status_t HSA_API hsa_code_symbol_get_info( - hsa_code_symbol_t code_symbol, - hsa_code_symbol_info_t attribute, - void *value); - -/** - * @brief Iterate over the symbols in a code object, and invoke an - * application-defined callback on every iteration. - * - * @param[in] code_object Code object. - * - * @param[in] callback Callback to be invoked once per code object symbol. The - * HSA runtime passes three arguments to the callback: the code object, a - * symbol, and the application data. If @p callback returns a status other than - * ::HSA_STATUS_SUCCESS for a particular iteration, the traversal stops and - * ::hsa_code_object_iterate_symbols 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_CODE_OBJECT @p code_object is invalid. - * - * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL. - */ -hsa_status_t HSA_API hsa_code_object_iterate_symbols( - hsa_code_object_t code_object, - hsa_status_t (*callback)(hsa_code_object_t code_object, hsa_code_symbol_t symbol, void* data), - void* data); + bool *result); /** @} */ + /** \defgroup executable Executable * @{ */ /** - * @brief An opaque handle to an executable, which contains ISA for finalized - * kernels and indirect functions together with the allocated global/readonly - * segment variables they reference. + * @brief Code object reader handle. A code object reader is used to + * load a code object from file (when created using + * ::hsa_code_object_reader_create_from_file), or from memory (if created using + * ::hsa_code_object_reader_create_from_memory). + */ +typedef struct hsa_code_object_reader_s { + /** + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. + */ + uint64_t handle; +} hsa_code_object_reader_t; + +/** + * @brief Create a code object reader to operate on a file. + * + * @param[in] file File descriptor. The file must have been opened by + * application with at least read permissions prior calling this function. The + * file must contain a vendor-specific code object. + * + * The file is owned and managed by the application; the lifetime of the file + * descriptor must exceed that of any associated code object reader. + * + * @param[out] code_object_reader Memory location to store the newly created + * code object reader handle. Must not be NULL. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_INVALID_FILE @p file is invalid. + * + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p code_object_reader is NULL. + */ +hsa_status_t HSA_API hsa_code_object_reader_create_from_file( + hsa_file_t file, + hsa_code_object_reader_t *code_object_reader); + +/** + * @brief Create a code object reader to operate on memory. + * + * @param[in] code_object Memory buffer that contains a vendor-specific code + * object. The buffer is owned and managed by the application; the lifetime of + * the buffer must exceed that of any associated code object reader. + * + * @param[in] size Size of the buffer pointed to by @p code_object. Must not be + * 0. + * + * @param[out] code_object_reader Memory location to store newly created code + * object reader handle. Must not be NULL. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p code_object is NULL, @p size + * is zero, or @p code_object_reader is NULL. + */ +hsa_status_t HSA_API hsa_code_object_reader_create_from_memory( + const void *code_object, + size_t size, + hsa_code_object_reader_t *code_object_reader); + +/** + * @brief Destroy a code object reader. + * + * @details The code object reader handle becomes invalid after completion of + * this function. Any file or memory used to create the code object read is not + * closed, removed, or deallocated by this function. + * + * @param[in] code_object_reader Code object reader to destroy. + * + * @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_CODE_OBJECT_READER @p code_object_reader + * is invalid. + */ +hsa_status_t HSA_API hsa_code_object_reader_destroy( + hsa_code_object_reader_t code_object_reader); + +/** + * @brief Struct containing an opaque handle to an executable, which contains + * ISA for finalized kernels and indirect functions together with the allocated + * global or readonly segment variables they reference. */ typedef struct hsa_executable_s { /** - * Opaque handle. + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. */ uint64_t handle; } hsa_executable_t; @@ -3128,13 +4078,17 @@ typedef enum { /** * Executable state, which allows the user to query variable addresses, * kernel code handles, and indirect function code handles using query - * operation. Loading new code objects, as well as defining external variables - * is not allowed in this state. + * operations. Loading new code objects, as well as defining external + * variables, is not allowed in this state. */ HSA_EXECUTABLE_STATE_FROZEN = 1 } hsa_executable_state_t; /** + * @deprecated Use ::hsa_executable_create_alt instead, which allows the + * application to specify the default floating-point rounding mode of the + * executable and assumes an unfrozen initial state. + * * @brief Create an empty executable. * * @param[in] profile Profile used in the executable. @@ -3143,9 +4097,13 @@ typedef enum { * ::HSA_EXECUTABLE_STATE_FROZEN, the resulting executable is useless because no * code objects can be loaded, and no variables can be defined. * - * @param[in] options Vendor-specific options. May be NULL. + * @param[in] options Standard and vendor-specific options. Unknown options are + * ignored. A standard option begins with the "-hsa_" prefix. Options beginning + * with the "-hsa_ext__" prefix are reserved for extensions. A + * vendor-specific option begins with the "-_" prefix. Must be a + * NUL-terminated string. May be NULL. * - * @param[out] executable Memory location where the HSA runtime stores newly + * @param[out] executable Memory location where the HSA runtime stores the newly * created executable handle. * * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. @@ -3153,26 +4111,62 @@ typedef enum { * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been * initialized. * - * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES There is a failure to allocate - * resources required for the operation. + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p profile is invalid, or * @p executable is NULL. */ -hsa_status_t HSA_API hsa_executable_create( +hsa_status_t HSA_API HSA_DEPRECATED hsa_executable_create( hsa_profile_t profile, hsa_executable_state_t executable_state, const char *options, hsa_executable_t *executable); +/** + * @brief Create an empty executable. + * + * @param[in] profile Profile used in the executable. + * + * @param[in] default_float_rounding_mode Default floating-point rounding mode + * used in the executable. Allowed rounding modes are near and zero (default is + * not allowed). + * + * @param[in] options Standard and vendor-specific options. Unknown options are + * ignored. A standard option begins with the "-hsa_" prefix. Options beginning + * with the "-hsa_ext__" prefix are reserved for extensions. A + * vendor-specific option begins with the "-_" prefix. Must be a + * NUL-terminated string. May be NULL. + * + * @param[out] executable Memory location where the HSA runtime stores newly + * created executable handle. The initial state of the executable is + * ::HSA_EXECUTABLE_STATE_UNFROZEN. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p profile is invalid, or + * @p executable is NULL. + */ +hsa_status_t HSA_API hsa_executable_create_alt( + hsa_profile_t profile, + hsa_default_float_rounding_mode_t default_float_rounding_mode, + const char *options, + hsa_executable_t *executable); + /** * @brief Destroy an executable. * - * @details Executable handle becomes invalid after the executable has been + * @details An executable handle becomes invalid after the executable has been * destroyed. Code object handles that were loaded into this executable are * still valid after the executable has been destroyed, and can be used as * intended. Resources allocated outside and associated with this executable - * (such as external global/readonly variables) can be released after the + * (such as external global or readonly variables) can be released after the * executable has been destroyed. * * Executable should not be destroyed while kernels are in flight. @@ -3190,67 +4184,149 @@ hsa_status_t HSA_API hsa_executable_destroy( hsa_executable_t executable); /** - * @brief Load code object into the executable. + * @brief Loaded code object handle. + */ +typedef struct hsa_loaded_code_object_s { + /** + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. + */ + uint64_t handle; +} hsa_loaded_code_object_t; + +/** + * @brief Load a program code object into an executable. * - * @details Every global/readonly variable that is external must be defined - * using define set of operations before loading code objects. Internal - * global/readonly variable is allocated once the code object, that is being - * loaded, references this variable and this variable is not allocated. + * @details A program code object contains information about resources that are + * accessible by all kernel agents that run the executable, and can be loaded + * at most once into an executable. + * + * If the program code object uses extensions, the implementation must support + * them for this operation to return successfully. + * + * @param[in] executable Executable. + * + * @param[in] code_object_reader A code object reader that holds the program + * code object to load. If a code object reader is destroyed before all the + * associated executables are destroyed, the behavior is undefined. + * + * @param[in] options Standard and vendor-specific options. Unknown options are + * ignored. A standard option begins with the "-hsa_" prefix. Options beginning + * with the "-hsa_ext__" prefix are reserved for extensions. A + * vendor-specific option begins with the "-_" prefix. Must be a + * NUL-terminated string. May be NULL. + * + * @param[out] loaded_code_object Pointer to a memory location where the HSA + * runtime stores the loaded code object handle. 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_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. + * + * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE The executable is invalid. + * + * @retval ::HSA_STATUS_ERROR_FROZEN_EXECUTABLE The executable is frozen. + * + * @retval ::HSA_STATUS_ERROR_INVALID_CODE_OBJECT_READER @p code_object_reader + * is invalid. + * + * @retval ::HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS The program code object is + * not compatible with the executable or the implementation (for example, the + * code object uses an extension that is not supported by the implementation). + */ +hsa_status_t HSA_API hsa_executable_load_program_code_object( + hsa_executable_t executable, + hsa_code_object_reader_t code_object_reader, + const char *options, + hsa_loaded_code_object_t *loaded_code_object); + +/** + * @brief Load an agent code object into an executable. + * + * @details The agent code object contains all defined agent + * allocation variables, functions, indirect functions, and kernels in a given + * program for a given instruction set architecture. * * Any module linkage declaration must have been defined either by a define * variable or by loading a code object that has a symbol with module linkage * definition. * + * The default floating-point rounding mode of the code object associated with + * @p code_object_reader must match that of the executable + * (::HSA_EXECUTABLE_INFO_DEFAULT_FLOAT_ROUNDING_MODE), or be default (in which + * case the value of ::HSA_EXECUTABLE_INFO_DEFAULT_FLOAT_ROUNDING_MODE is used). + * If the agent code object uses extensions, the implementation and the agent + * must support them for this operation to return successfully. + * * @param[in] executable Executable. * - * @param[in] agent Agent to load code object for. The agent must support the - * default floating-point rounding mode used by @p code_object. + * @param[in] agent Agent to load code object for. A code object can be loaded + * into an executable at most once for a given agent. The instruction set + * architecture of the code object must be supported by the agent. * - * @param[in] code_object Code object to load. The lifetime of the code object - * must exceed that of the executable: if @p code_object is destroyed before @p - * executable, the behavior is undefined. + * @param[in] code_object_reader A code object reader that holds the code object + * to load. If a code object reader is destroyed before all the associated + * executables are destroyed, the behavior is undefined. * - * @param[in] options Vendor-specific options. May be NULL. + * @param[in] options Standard and vendor-specific options. Unknown options are + * ignored. A standard option begins with the "-hsa_" prefix. Options beginning + * with the "-hsa_ext__" prefix are reserved for extensions. A + * vendor-specific option begins with the "-_" prefix. Must be a + * NUL-terminated string. May be NULL. + * + * @param[out] loaded_code_object Pointer to a memory location where the HSA + * runtime stores the loaded code object handle. 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_OUT_OF_RESOURCES There is a failure to allocate - * resources required for the operation. + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE The executable is invalid. * + * @retval ::HSA_STATUS_ERROR_FROZEN_EXECUTABLE The executable is frozen. + * * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid. * - * @retval ::HSA_STATUS_ERROR_INVALID_CODE_OBJECT @p code_object is invalid. + * @retval ::HSA_STATUS_ERROR_INVALID_CODE_OBJECT_READER @p code_object_reader + * is invalid. * - * @retval ::HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS @p agent is not compatible - * with @p code_object (for example, @p agent does not support the default - * floating-point rounding mode specified by @p code_object), or @p code_object - * is not compatible with @p executable (for example, @p code_object and @p - * executable have different machine models or profiles). - * - * @retval ::HSA_STATUS_ERROR_FROZEN_EXECUTABLE @p executable is frozen. + * @retval ::HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS The code object read by @p + * code_object_reader is not compatible with the agent (for example, the agent + * does not support the instruction set architecture of the code object), the + * executable (for example, there is a default floating-point mode mismatch + * between the two), or the implementation. */ -hsa_status_t HSA_API hsa_executable_load_code_object( +hsa_status_t HSA_API hsa_executable_load_agent_code_object( hsa_executable_t executable, hsa_agent_t agent, - hsa_code_object_t code_object, - const char *options); + hsa_code_object_reader_t code_object_reader, + const char *options, + hsa_loaded_code_object_t *loaded_code_object); /** * @brief Freeze the executable. * - * @details No modifications to executable can be made after freezing: no - * code objects can be loaded to the executable, no external variables can - * be defined. Freezing the executable does not prevent querying executable's - * attributes. + * @details No modifications to executable can be made after freezing: no code + * objects can be loaded to the executable, and no external variables can be + * defined. Freezing the executable does not prevent querying the executable's + * attributes. The application must define all the external variables in an + * executable before freezing it. * * @param[in] executable Executable. * - * @param[in] options Vendor-specific options. May be NULL. + * @param[in] options Standard and vendor-specific options. Unknown options are + * ignored. A standard option begins with the "-hsa_" prefix. Options beginning + * with the "-hsa_ext__" prefix are reserved for extensions. A + * vendor-specific option begins with the "-_" prefix. Must be a + * NUL-terminated string. May be NULL. * * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. * @@ -3259,7 +4335,7 @@ hsa_status_t HSA_API hsa_executable_load_code_object( * * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE The executable is invalid. * - * @retval ::HSA_STATUS_ERROR_VARIABLE_UNDEFINED One or more variable is + * @retval ::HSA_STATUS_ERROR_VARIABLE_UNDEFINED One or more variables are * undefined in the executable. * * @retval ::HSA_STATUS_ERROR_FROZEN_EXECUTABLE @p executable is already frozen. @@ -3280,7 +4356,12 @@ typedef enum { /** * Executable state. The type of this attribute is ::hsa_executable_state_t. */ - HSA_EXECUTABLE_INFO_STATE = 2 + HSA_EXECUTABLE_INFO_STATE = 2, + /** + * Default floating-point rounding mode specified when executable was created. + * The type of this attribute is ::hsa_default_float_rounding_mode_t. + */ + HSA_EXECUTABLE_INFO_DEFAULT_FLOAT_ROUNDING_MODE = 3 } hsa_executable_info_t; /** @@ -3317,23 +4398,23 @@ hsa_status_t HSA_API hsa_executable_get_info( * variable must be defined before loading a code object into an executable. * In addition, code objects loaded must not define the variable. * - * @param[in] executable Executable. + * @param[in] executable Executable. Must not be in frozen state. * - * @param[in] variable_name Name of the variable. + * @param[in] variable_name Name of the variable. The Programmer's Reference + * Manual describes the standard name mangling scheme. * - * @param[in] address Address where the variable is defined. The buffer pointed - * by @p address is owned by the application, and cannot be deallocated before - * @p executable is destroyed. + * @param[in] address Address where the variable is defined. This address must + * be in global memory and can be read and written by any agent in the + * system. The application cannot deallocate the buffer pointed by @p address + * before @p executable is destroyed. * * @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 a failure to allocate - * resources required for the operation. - * - * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p variable_name is NULL. + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE The executable is invalid. * @@ -3344,6 +4425,8 @@ hsa_status_t HSA_API hsa_executable_get_info( * @p variable_name. * * @retval ::HSA_STATUS_ERROR_FROZEN_EXECUTABLE @p executable is frozen. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p variable_name is NULL. */ hsa_status_t HSA_API hsa_executable_global_variable_define( hsa_executable_t executable, @@ -3358,25 +4441,25 @@ hsa_status_t HSA_API hsa_executable_global_variable_define( * variable must be defined before loading a code object into an executable. * In addition, code objects loaded must not define the variable. * - * @param[in] executable Executable. + * @param[in] executable Executable. Must not be in frozen state. * * @param[in] agent Agent for which the variable is being defined. * - * @param[in] variable_name Name of the variable. + * @param[in] variable_name Name of the variable. The Programmer's Reference + * Manual describes the standard name mangling scheme. * - * @param[in] address Address where the variable is defined. The buffer pointed - * by @p address is owned by the application, and cannot be deallocated before - * @p executable is destroyed. + * @param[in] address Address where the variable is defined. This address must + * have been previously allocated using ::hsa_memory_allocate in a global region + * that is only visible to @p agent. The application cannot deallocate the + * buffer pointed by @p address before @p executable is destroyed. * * @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 a failure to allocate - * resources required for the operation. - * - * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p variable_name is NULL. + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE The executable is invalid. * @@ -3389,6 +4472,8 @@ hsa_status_t HSA_API hsa_executable_global_variable_define( * @p variable_name. * * @retval ::HSA_STATUS_ERROR_FROZEN_EXECUTABLE @p executable is frozen. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p variable_name is NULL. */ hsa_status_t HSA_API hsa_executable_agent_global_variable_define( hsa_executable_t executable, @@ -3404,11 +4489,17 @@ hsa_status_t HSA_API hsa_executable_agent_global_variable_define( * before loading a code object into an executable. In addition, code objects * loaded must not define the variable. * - * @param[in] executable Executable. + * @param[in] executable Executable. Must not be in frozen state. * * @param[in] agent Agent for which the variable is being defined. * - * @param[in] variable_name Name of the variable. + * @param[in] variable_name Name of the variable. The Programmer's Reference + * Manual describes the standard name mangling scheme. + * + * @param[in] address Address where the variable is defined. This address must + * have been previously allocated using ::hsa_memory_allocate in a readonly + * region associated with @p agent. The application cannot deallocate the buffer + * pointed by @p address before @p executable is destroyed. * * @param[in] address Address where the variable is defined. The buffer pointed * by @p address is owned by the application, and cannot be deallocated before @@ -3419,10 +4510,8 @@ hsa_status_t HSA_API hsa_executable_agent_global_variable_define( * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been * initialized. * - * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES There is a failure to allocate - * resources required for the operation. - * - * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p variable_name is NULL. + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. * * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE Executable is invalid. * @@ -3435,6 +4524,8 @@ hsa_status_t HSA_API hsa_executable_agent_global_variable_define( * @p variable_name. * * @retval ::HSA_STATUS_ERROR_FROZEN_EXECUTABLE @p executable is frozen. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p variable_name is NULL. */ hsa_status_t HSA_API hsa_executable_readonly_variable_define( hsa_executable_t executable, @@ -3443,15 +4534,17 @@ hsa_status_t HSA_API hsa_executable_readonly_variable_define( void *address); /** - * @brief Validate executable. Checks that all code objects have matching + * @brief Validate an executable. Checks that all code objects have matching * machine model, profile, and default floating-point rounding mode. Checks that * all declarations have definitions. Checks declaration-definition - * compatibility (see HSA Programming Reference Manual for compatibility rules). + * compatibility (see the HSA Programming Reference Manual for compatibility + * rules). Invoking this function is equivalent to invoking + * ::hsa_executable_validate_alt with no options. * - * @param[in] executable Executable. + * @param[in] executable Executable. Must be in frozen state. * * @param[out] result Memory location where the HSA runtime stores the - * validation result. If the executable is valid, the result is 0. + * validation result. If the executable passes validation, the result is 0. * * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. * @@ -3464,19 +4557,58 @@ hsa_status_t HSA_API hsa_executable_readonly_variable_define( */ hsa_status_t HSA_API hsa_executable_validate( hsa_executable_t executable, - uint32_t* result); + uint32_t *result); /** - * @brief Executable symbol. + * @brief Validate an executable. Checks that all code objects have matching + * machine model, profile, and default floating-point rounding mode. Checks that + * all declarations have definitions. Checks declaration-definition + * compatibility (see the HSA Programming Reference Manual for compatibility + * rules). + * + * @param[in] executable Executable. Must be in frozen state. + * + * @param[in] options Standard and vendor-specific options. Unknown options are + * ignored. A standard option begins with the "-hsa_" prefix. Options beginning + * with the "-hsa_ext__" prefix are reserved for extensions. A + * vendor-specific option begins with the "-_" prefix. Must be a + * NUL-terminated string. May be NULL. + * + * @param[out] result Memory location where the HSA runtime stores the + * validation result. If the executable passes validation, the result is 0. + * + * @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_EXECUTABLE @p executable is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p result is NULL. + */ +hsa_status_t HSA_API hsa_executable_validate_alt( + hsa_executable_t executable, + const char *options, + uint32_t *result); + +/** + * @brief Executable symbol handle. + * + * The lifetime of an executable object symbol matches that of the executable + * associated with it. An operation on a symbol whose associated executable has + * been destroyed results in undefined behavior. */ typedef struct hsa_executable_symbol_s { /** - * Opaque handle. + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. */ uint64_t handle; } hsa_executable_symbol_t; /** + * @deprecated Use ::hsa_executable_get_symbol_by_name instead. + * * @brief Get the symbol handle for a given a symbol name. * * @param[in] executable Executable. @@ -3509,7 +4641,7 @@ typedef struct hsa_executable_symbol_s { * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p symbol_name is NULL, or * @p symbol is NULL. */ -hsa_status_t HSA_API hsa_executable_get_symbol( +hsa_status_t HSA_API HSA_DEPRECATED hsa_executable_get_symbol( hsa_executable_t executable, const char *module_name, const char *symbol_name, @@ -3517,6 +4649,101 @@ hsa_status_t HSA_API hsa_executable_get_symbol( int32_t call_convention, hsa_executable_symbol_t *symbol); +/** + * @brief Retrieve the symbol handle corresponding to a given a symbol name. + * + * @param[in] executable Executable. + * + * @param[in] symbol_name Symbol name. Must be a NUL-terminated character + * array. The Programmer's Reference Manual describes the standard name mangling + * scheme. + * + * @param[in] agent Pointer to the agent for which the symbol with the given + * name is defined. If the symbol corresponding to the given name has program + * allocation, @p agent must be NULL. + * + * @param[out] symbol Memory location where the HSA runtime stores the symbol + * handle. Must not be NULL. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE The executable is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_SYMBOL_NAME There is no symbol with a name + * that matches @p symbol_name. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p symbol_name is NULL, or @p + * symbol is NULL. + */ +hsa_status_t HSA_API hsa_executable_get_symbol_by_name( + hsa_executable_t executable, + const char *symbol_name, + const hsa_agent_t *agent, + hsa_executable_symbol_t *symbol); + +/** + * @brief Symbol type. + */ +typedef enum { + /** + * Variable. + */ + HSA_SYMBOL_KIND_VARIABLE = 0, + /** + * Kernel. + */ + HSA_SYMBOL_KIND_KERNEL = 1, + /** + * Indirect function. + */ + HSA_SYMBOL_KIND_INDIRECT_FUNCTION = 2 +} hsa_symbol_kind_t; + +/** + * @brief Linkage type of a symbol. + */ +typedef enum { + /** + * Module linkage. + */ + HSA_SYMBOL_LINKAGE_MODULE = 0, + /** + * Program linkage. + */ + HSA_SYMBOL_LINKAGE_PROGRAM = 1 +} hsa_symbol_linkage_t; + +/** + * @brief Allocation type of a variable. + */ +typedef enum { + /** + * Agent allocation. + */ + HSA_VARIABLE_ALLOCATION_AGENT = 0, + /** + * Program allocation. + */ + HSA_VARIABLE_ALLOCATION_PROGRAM = 1 +} hsa_variable_allocation_t; + +/** + * @brief Memory segment associated with a variable. + */ +typedef enum { + /** + * Global memory segment. + */ + HSA_VARIABLE_SEGMENT_GLOBAL = 0, + /** + * Readonly memory segment. + */ + HSA_VARIABLE_SEGMENT_READONLY = 1 +} hsa_variable_segment_t; + /** * @brief Executable symbol attributes. */ @@ -3526,29 +4753,36 @@ typedef enum { */ HSA_EXECUTABLE_SYMBOL_INFO_TYPE = 0, /** - * The length of the symbol name. The type of this attribute is uint32_t. + * The length of the symbol name in bytes, not including the NUL terminator. + * The type of this attribute is uint32_t. */ HSA_EXECUTABLE_SYMBOL_INFO_NAME_LENGTH = 1, /** * The name of the symbol. The type of this attribute is character array with * the length equal to the value of ::HSA_EXECUTABLE_SYMBOL_INFO_NAME_LENGTH - * attribute + * attribute. */ HSA_EXECUTABLE_SYMBOL_INFO_NAME = 2, /** - * The length of the module name to which this symbol belongs if this symbol - * has module linkage, otherwise 0 is returned. The type of this attribute is - * uint32_t. + * @deprecated + * + * The length of the module name in bytes (not including the NUL terminator) + * to which this symbol belongs if this symbol has module linkage, otherwise 0 + * is returned. The type of this attribute is uint32_t. */ HSA_EXECUTABLE_SYMBOL_INFO_MODULE_NAME_LENGTH = 3, /** + * @deprecated + * * The module name to which this symbol belongs if this symbol has module - * linkage, otherwise empty string is returned. The type of this attribute is - * character array with the length equal to the value of + * linkage, otherwise an empty string is returned. The type of this attribute + * is character array with the length equal to the value of * ::HSA_EXECUTABLE_SYMBOL_INFO_MODULE_NAME_LENGTH attribute. */ HSA_EXECUTABLE_SYMBOL_INFO_MODULE_NAME = 4, /** + * @deprecated + * * Agent associated with this symbol. If the symbol is a variable, the * value of this attribute is only defined if * ::HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_ALLOCATION is @@ -3574,23 +4808,34 @@ typedef enum { */ HSA_EXECUTABLE_SYMBOL_INFO_IS_DEFINITION = 17, /** + * @deprecated + * * The allocation kind of the variable. The value of this attribute is * undefined if the symbol is not a variable. The type of this attribute is * ::hsa_variable_allocation_t. */ HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_ALLOCATION = 6, /** + * @deprecated + * * The segment kind of the variable. The value of this attribute is undefined * if the symbol is not a variable. The type of this attribute is * ::hsa_variable_segment_t. */ HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_SEGMENT = 7, /** - * Alignment of the variable. The value of this attribute is undefined if - * the symbol is not a variable. The type of this attribute is uint32_t. + * @deprecated + * + * Alignment of the symbol in memory. The value of this attribute is undefined + * if the symbol is not a variable. The type of this attribute is uint32_t. + * + * The current alignment of the variable in memory may be greater than the + * value specified in the source program variable declaration. */ HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_ALIGNMENT = 8, /** + * @deprecated + * * Size of the variable. The value of this attribute is undefined if * the symbol is not a variable. The type of this attribute is uint32_t. * @@ -3599,6 +4844,8 @@ typedef enum { */ HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_SIZE = 9, /** + * @deprecated + * * Indicates whether the variable is constant. The value of this attribute is * undefined if the symbol is not a variable. The type of this attribute is * bool. @@ -3615,8 +4862,9 @@ typedef enum { HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_OBJECT = 22, /** * Size of kernarg segment memory that is required to hold the values of the - * kernel arguments, in bytes. The value of this attribute is undefined if the - * symbol is not a kernel. The type of this attribute is uint32_t. + * kernel arguments, in bytes. Must be a multiple of 16. The value of this + * attribute is undefined if the symbol is not a kernel. The type of this + * attribute is uint32_t. */ HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_KERNARG_SEGMENT_SIZE = 11, /** @@ -3657,18 +4905,27 @@ typedef enum { * functions, or the HSAIL alloca instruction are present in the kernel. */ HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_DYNAMIC_CALLSTACK = 15, + /** + * @deprecated + * + * Call convention of the kernel. The value of this attribute is undefined if + * the symbol is not a kernel. The type of this attribute is uint32_t. + */ + HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_CALL_CONVENTION = 18, /** * Indirect function object handle. The value of this attribute is undefined * if the symbol is not an indirect function, or the associated agent does * not support the Full Profile. The type of this attribute depends on the - * machine model: if machine model is small, then the type is uint32_t, if - * machine model is large, then the type is uint64_t. + * machine model: the type is uint32_t for small machine model, and uint64_t + * for large model. * * If the state of the executable is ::HSA_EXECUTABLE_STATE_UNFROZEN, then 0 * is returned. */ HSA_EXECUTABLE_SYMBOL_INFO_INDIRECT_FUNCTION_OBJECT = 23, /** + * @deprecated + * * Call convention of the indirect function. The value of this attribute is * undefined if the symbol is not an indirect function, or the associated * agent does not support the Full Profile. The type of this attribute is @@ -3693,6 +4950,9 @@ typedef enum { * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been * initialized. * + * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE_SYMBOL The executable symbol is + * invalid. + * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p attribute is an invalid * executable symbol attribute, or @p value is NULL. */ @@ -3702,6 +4962,8 @@ hsa_status_t HSA_API hsa_executable_symbol_get_info( void *value); /** + * @deprecated + * * @brief Iterate over the symbols in a executable, and invoke an * application-defined callback on every iteration. * @@ -3721,14 +4983,649 @@ hsa_status_t HSA_API hsa_executable_symbol_get_info( * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been * initialized. * - * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE Th executable is invalid. + * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE The executable is invalid. * * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL. */ -hsa_status_t HSA_API hsa_executable_iterate_symbols( +hsa_status_t HSA_API HSA_DEPRECATED hsa_executable_iterate_symbols( hsa_executable_t executable, - hsa_status_t (*callback)(hsa_executable_t executable, hsa_executable_symbol_t symbol, void* data), - void* data); + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_executable_symbol_t symbol, + void *data), + void *data); + +/** + * @brief Iterate over the kernels, indirect functions, and agent allocation + * variables in an executable for a given agent, and invoke an application- + * defined callback on every iteration. + * + * @param[in] executable Executable. + * + * @param[in] agent Agent. + * + * @param[in] callback Callback to be invoked once per executable symbol. The + * HSA runtime passes three arguments to the callback: the executable, a symbol, + * and the application data. If @p callback returns a status other than + * ::HSA_STATUS_SUCCESS for a particular iteration, the traversal stops and + * ::hsa_executable_iterate_symbols 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_EXECUTABLE The executable is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL. + */ +hsa_status_t HSA_API hsa_executable_iterate_agent_symbols( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_agent_t agent, + hsa_executable_symbol_t symbol, + void *data), + void *data); + +/** + * @brief Iterate over the program allocation variables in an executable, and + * invoke an application-defined callback on every iteration. + * + * @param[in] executable Executable. + * + * @param[in] callback Callback to be invoked once per executable symbol. The + * HSA runtime passes three arguments to the callback: the executable, a symbol, + * and the application data. If @p callback returns a status other than + * ::HSA_STATUS_SUCCESS for a particular iteration, the traversal stops and + * ::hsa_executable_iterate_symbols 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_EXECUTABLE The executable is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL. + */ +hsa_status_t HSA_API hsa_executable_iterate_program_symbols( + hsa_executable_t executable, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_executable_symbol_t symbol, + void *data), + void *data); + +/** @} */ + + +/** \defgroup code-object Code Objects (deprecated). + * @{ + */ + +/** + * @deprecated + * + * @brief Struct containing an opaque handle to a code object, which contains + * ISA for finalized kernels and indirect functions together with information + * about the global or readonly segment variables they reference. + */ +typedef struct hsa_code_object_s { + /** + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. + */ + uint64_t handle; +} hsa_code_object_t; + +/** + * @deprecated + * + * @brief Application data handle that is passed to the serialization + * and deserialization functions. + */ +typedef struct hsa_callback_data_s { + /** + * Opaque handle. + */ + uint64_t handle; +} hsa_callback_data_t; + +/** + * @deprecated + * + * @brief Serialize a code object. Can be used for offline finalization, + * install-time finalization, disk code caching, etc. + * + * @param[in] code_object Code object. + * + * @param[in] alloc_callback Callback function for memory allocation. Must not + * be NULL. The HSA runtime passes three arguments to the callback: the + * allocation size, the application data, and a pointer to a memory location + * where the application stores the allocation result. The HSA runtime invokes + * @p alloc_callback once to allocate a buffer that contains the serialized + * version of @p code_object. If the callback returns a status code other than + * ::HSA_STATUS_SUCCESS, this function returns the same code. + * + * @param[in] callback_data Application data that is passed to @p + * alloc_callback. May be NULL. + * + * @param[in] options Standard and vendor-specific options. Unknown options are + * ignored. A standard option begins with the "-hsa_" prefix. Options beginning + * with the "-hsa_ext__" prefix are reserved for extensions. A + * vendor-specific option begins with the "-_" prefix. Must be a + * NUL-terminated string. May be NULL. + * + * @param[out] serialized_code_object Memory location where the HSA runtime + * stores a pointer to the serialized code object. Must not be NULL. + * + * @param[out] serialized_code_object_size Memory location where the HSA runtime + * stores the size (in bytes) of @p serialized_code_object. The returned value + * matches the allocation size passed by the HSA runtime to @p + * alloc_callback. Must not be NULL. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. + * + * @retval ::HSA_STATUS_ERROR_INVALID_CODE_OBJECT @p code_object is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p alloc_callback, @p + * serialized_code_object, or @p serialized_code_object_size are NULL. + */ +hsa_status_t HSA_API HSA_DEPRECATED hsa_code_object_serialize( + hsa_code_object_t code_object, + hsa_status_t (*alloc_callback)(size_t size, + hsa_callback_data_t data, + void **address), + hsa_callback_data_t callback_data, + const char *options, + void **serialized_code_object, + size_t *serialized_code_object_size); + +/** + * @deprecated + * + * @brief Deserialize a code object. + * + * @param[in] serialized_code_object A serialized code object. Must not be NULL. + * + * @param[in] serialized_code_object_size The size (in bytes) of @p + * serialized_code_object. Must not be 0. + * + * @param[in] options Standard and vendor-specific options. Unknown options are + * ignored. A standard option begins with the "-hsa_" prefix. Options beginning + * with the "-hsa_ext__" prefix are reserved for extensions. A + * vendor-specific option begins with the "-_" prefix. Must be a + * NUL-terminated string. May be NULL. + * + * @param[out] code_object Memory location where the HSA runtime stores the + * deserialized code object. + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p serialized_code_object, or @p + * code_object are NULL, or @p serialized_code_object_size is 0. + */ +hsa_status_t HSA_API HSA_DEPRECATED hsa_code_object_deserialize( + void *serialized_code_object, + size_t serialized_code_object_size, + const char *options, + hsa_code_object_t *code_object); + +/** + * @deprecated + * + * @brief Destroy a code object. + * + * @details The lifetime of a code object must exceed that of any executable + * where it has been loaded. If an executable that loaded @p code_object has not + * been destroyed, the behavior is undefined. + * + * @param[in] code_object Code object. The handle becomes invalid after it has + * been destroyed. + * + * @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_CODE_OBJECT @p code_object is invalid. + */ +hsa_status_t HSA_API HSA_DEPRECATED hsa_code_object_destroy( + hsa_code_object_t code_object); + +/** + * @deprecated + * + * @brief Code object type. + */ +typedef enum { + /** + * Produces code object that contains ISA for all kernels and indirect + * functions in HSA source. + */ + HSA_CODE_OBJECT_TYPE_PROGRAM = 0 +} hsa_code_object_type_t; + +/** + * @deprecated + * + * @brief Code object attributes. + */ +typedef enum { + /** + * The version of the code object. The type of this attribute is a + * NUL-terminated char[64]. The name must be at most 63 characters long (not + * including the NUL terminator) and all array elements not used for the name + * must be NUL. + */ + HSA_CODE_OBJECT_INFO_VERSION = 0, + /** + * Type of code object. The type of this attribute is + * ::hsa_code_object_type_t. + */ + HSA_CODE_OBJECT_INFO_TYPE = 1, + /** + * Instruction set architecture this code object is produced for. The type of + * this attribute is ::hsa_isa_t. + */ + HSA_CODE_OBJECT_INFO_ISA = 2, + /** + * Machine model this code object is produced for. The type of this attribute + * is ::hsa_machine_model_t. + */ + HSA_CODE_OBJECT_INFO_MACHINE_MODEL = 3, + /** + * Profile this code object is produced for. The type of this attribute is + * ::hsa_profile_t. + */ + HSA_CODE_OBJECT_INFO_PROFILE = 4, + /** + * Default floating-point rounding mode used when the code object is + * produced. The type of this attribute is + * ::hsa_default_float_rounding_mode_t. + */ + HSA_CODE_OBJECT_INFO_DEFAULT_FLOAT_ROUNDING_MODE = 5 +} hsa_code_object_info_t; + +/** + * @deprecated + * + * @brief Get the current value of an attribute for a given code object. + * + * @param[in] code_object Code object. + * + * @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_CODE_OBJECT @p code_object is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p attribute is an invalid + * code object attribute, or @p value is NULL. + */ +hsa_status_t HSA_API HSA_DEPRECATED hsa_code_object_get_info( + hsa_code_object_t code_object, + hsa_code_object_info_t attribute, + void *value); + +/** + * @deprecated + * + * @brief Load code object into the executable. + * + * @details Every global or readonly variable that is external must be defined + * before loading the code object. An internal global or readonly variable is + * allocated once the code object, that is being loaded, references this + * variable and this variable is not allocated. + * + * Any module linkage declaration must have been defined either by a define + * variable or by loading a code object that has a symbol with module linkage + * definition. + * + * @param[in] executable Executable. + * + * @param[in] agent Agent to load code object for. The agent must support the + * default floating-point rounding mode used by @p code_object. + * + * @param[in] code_object Code object to load. The lifetime of the code object + * must exceed that of the executable: if @p code_object is destroyed before @p + * executable, the behavior is undefined. + * + * @param[in] options Standard and vendor-specific options. Unknown options are + * ignored. A standard option begins with the "-hsa_" prefix. Options beginning + * with the "-hsa_ext__" prefix are reserved for extensions. A + * vendor-specific option begins with the "-_" prefix. Must be a + * NUL-terminated string. 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_OUT_OF_RESOURCES The HSA runtime failed to + * allocate the required resources. + * + * @retval ::HSA_STATUS_ERROR_INVALID_EXECUTABLE The executable is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_AGENT The agent is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_CODE_OBJECT @p code_object is invalid. + * + * @retval ::HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS @p agent is not compatible + * with @p code_object (for example, @p agent does not support the default + * floating-point rounding mode specified by @p code_object), or @p code_object + * is not compatible with @p executable (for example, @p code_object and @p + * executable have different machine models or profiles). + * + * @retval ::HSA_STATUS_ERROR_FROZEN_EXECUTABLE @p executable is frozen. + */ +hsa_status_t HSA_API HSA_DEPRECATED hsa_executable_load_code_object( + hsa_executable_t executable, + hsa_agent_t agent, + hsa_code_object_t code_object, + const char *options); + +/** + * @deprecated + * + * @brief Code object symbol handle. + * + * The lifetime of a code object symbol matches that of the code object + * associated with it. An operation on a symbol whose associated code object has + * been destroyed results in undefined behavior. + */ +typedef struct hsa_code_symbol_s { + /** + * Opaque handle. Two handles reference the same object of the enclosing type + * if and only if they are equal. + */ + uint64_t handle; +} hsa_code_symbol_t; + +/** + * @deprecated + * + * @brief Get the symbol handle within a code object for a given a symbol name. + * + * @param[in] code_object Code object. + * + * @param[in] symbol_name Symbol name. + * + * @param[out] symbol Memory location where the HSA runtime stores the symbol + * 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_INVALID_CODE_OBJECT @p code_object is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_SYMBOL_NAME There is no symbol with a name + * that matches @p symbol_name. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p symbol_name is NULL, or + * @p symbol is NULL. + */ +hsa_status_t HSA_API HSA_DEPRECATED hsa_code_object_get_symbol( + hsa_code_object_t code_object, + const char *symbol_name, + hsa_code_symbol_t *symbol); + +/** + * @deprecated + * + * @brief Get the symbol handle within a code object for a given a symbol name. + * + * @param[in] code_object Code object. + * + * @param[in] module_name Module name. Must be NULL if the symbol has + * program linkage. + * + * @param[in] symbol_name Symbol name. + * + * @param[out] symbol Memory location where the HSA runtime stores the symbol + * 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_INVALID_CODE_OBJECT @p code_object is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_SYMBOL_NAME There is no symbol with a name + * that matches @p symbol_name. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p symbol_name is NULL, or + * @p symbol is NULL. + */ +hsa_status_t HSA_API HSA_DEPRECATED hsa_code_object_get_symbol_from_name( + hsa_code_object_t code_object, + const char *module_name, + const char *symbol_name, + hsa_code_symbol_t *symbol); + +/** + * @deprecated + * + * @brief Code object symbol attributes. + */ +typedef enum { + /** + * The type of the symbol. The type of this attribute is ::hsa_symbol_kind_t. + */ + HSA_CODE_SYMBOL_INFO_TYPE = 0, + /** + * The length of the symbol name in bytes, not including the NUL terminator. + * The type of this attribute is uint32_t. + */ + HSA_CODE_SYMBOL_INFO_NAME_LENGTH = 1, + /** + * The name of the symbol. The type of this attribute is character array with + * the length equal to the value of ::HSA_CODE_SYMBOL_INFO_NAME_LENGTH + * attribute. + */ + HSA_CODE_SYMBOL_INFO_NAME = 2, + /** + * The length of the module name in bytes (not including the NUL terminator) + * to which this symbol belongs if this symbol has module linkage, otherwise 0 + * is returned. The type of this attribute is uint32_t. + */ + HSA_CODE_SYMBOL_INFO_MODULE_NAME_LENGTH = 3, + /** + * The module name to which this symbol belongs if this symbol has module + * linkage, otherwise an empty string is returned. The type of this attribute + * is character array with the length equal to the value of + * ::HSA_CODE_SYMBOL_INFO_MODULE_NAME_LENGTH attribute. + */ + HSA_CODE_SYMBOL_INFO_MODULE_NAME = 4, + /** + * The linkage kind of the symbol. The type of this attribute is + * ::hsa_symbol_linkage_t. + */ + HSA_CODE_SYMBOL_INFO_LINKAGE = 5, + /** + * Indicates whether the symbol corresponds to a definition. The type of this + * attribute is bool. + */ + HSA_CODE_SYMBOL_INFO_IS_DEFINITION = 17, + /** + * The allocation kind of the variable. The value of this attribute is + * undefined if the symbol is not a variable. The type of this attribute is + * ::hsa_variable_allocation_t. + */ + HSA_CODE_SYMBOL_INFO_VARIABLE_ALLOCATION = 6, + /** + * The segment kind of the variable. The value of this attribute is + * undefined if the symbol is not a variable. The type of this attribute is + * ::hsa_variable_segment_t. + */ + HSA_CODE_SYMBOL_INFO_VARIABLE_SEGMENT = 7, + /** + * Alignment of the symbol in memory. The value of this attribute is undefined + * if the symbol is not a variable. The type of this attribute is uint32_t. + * + * The current alignment of the variable in memory may be greater than the + * value specified in the source program variable declaration. + */ + HSA_CODE_SYMBOL_INFO_VARIABLE_ALIGNMENT = 8, + /** + * Size of the variable. The value of this attribute is undefined if the + * symbol is not a variable. The type of this attribute is uint32_t. + * + * A size of 0 is returned if the variable is an external variable and has an + * unknown dimension. + */ + HSA_CODE_SYMBOL_INFO_VARIABLE_SIZE = 9, + /** + * Indicates whether the variable is constant. The value of this attribute is + * undefined if the symbol is not a variable. The type of this attribute is + * bool. + */ + HSA_CODE_SYMBOL_INFO_VARIABLE_IS_CONST = 10, + /** + * Size of kernarg segment memory that is required to hold the values of the + * kernel arguments, in bytes. Must be a multiple of 16. The value of this + * attribute is undefined if the symbol is not a kernel. The type of this + * attribute is uint32_t. + */ + HSA_CODE_SYMBOL_INFO_KERNEL_KERNARG_SEGMENT_SIZE = 11, + /** + * Alignment (in bytes) of the buffer used to pass arguments to the kernel, + * which is the maximum of 16 and the maximum alignment of any of the kernel + * arguments. The value of this attribute is undefined if the symbol is not a + * kernel. The type of this attribute is uint32_t. + */ + HSA_CODE_SYMBOL_INFO_KERNEL_KERNARG_SEGMENT_ALIGNMENT = 12, + /** + * Size of static group segment memory required by the kernel (per + * work-group), in bytes. The value of this attribute is undefined + * if the symbol is not a kernel. The type of this attribute is uint32_t. + * + * The reported amount does not include any dynamically allocated group + * segment memory that may be requested by the application when a kernel is + * dispatched. + */ + HSA_CODE_SYMBOL_INFO_KERNEL_GROUP_SEGMENT_SIZE = 13, + /** + * Size of static private, spill, and arg segment memory required by + * this kernel (per work-item), in bytes. The value of this attribute is + * undefined if the symbol is not a kernel. The type of this attribute is + * uint32_t. + * + * If the value of ::HSA_CODE_SYMBOL_INFO_KERNEL_DYNAMIC_CALLSTACK is true, + * the kernel may use more private memory than the reported value, and the + * application must add the dynamic call stack usage to @a + * private_segment_size when populating a kernel dispatch packet. + */ + HSA_CODE_SYMBOL_INFO_KERNEL_PRIVATE_SEGMENT_SIZE = 14, + /** + * Dynamic callstack flag. The value of this attribute is undefined if the + * symbol is not a kernel. The type of this attribute is bool. + * + * If this flag is set (the value is true), the kernel uses a dynamically + * sized call stack. This can happen if recursive calls, calls to indirect + * functions, or the HSAIL alloca instruction are present in the kernel. + */ + HSA_CODE_SYMBOL_INFO_KERNEL_DYNAMIC_CALLSTACK = 15, + /** + * Call convention of the kernel. The value of this attribute is undefined if + * the symbol is not a kernel. The type of this attribute is uint32_t. + */ + HSA_CODE_SYMBOL_INFO_KERNEL_CALL_CONVENTION = 18, + /** + * Call convention of the indirect function. The value of this attribute is + * undefined if the symbol is not an indirect function. The type of this + * attribute is uint32_t. + */ + HSA_CODE_SYMBOL_INFO_INDIRECT_FUNCTION_CALL_CONVENTION = 16 +} hsa_code_symbol_info_t; + +/** + * @deprecated + * + * @brief Get the current value of an attribute for a given code symbol. + * + * @param[in] code_symbol Code symbol. + * + * @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_CODE_SYMBOL The code symbol is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p attribute is an invalid + * code symbol attribute, or @p value is NULL. + */ +hsa_status_t HSA_API HSA_DEPRECATED hsa_code_symbol_get_info( + hsa_code_symbol_t code_symbol, + hsa_code_symbol_info_t attribute, + void *value); + +/** + * @deprecated + * + * @brief Iterate over the symbols in a code object, and invoke an + * application-defined callback on every iteration. + * + * @param[in] code_object Code object. + * + * @param[in] callback Callback to be invoked once per code object symbol. The + * HSA runtime passes three arguments to the callback: the code object, a + * symbol, and the application data. If @p callback returns a status other than + * ::HSA_STATUS_SUCCESS for a particular iteration, the traversal stops and + * ::hsa_code_object_iterate_symbols 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_CODE_OBJECT @p code_object is invalid. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p callback is NULL. + */ +hsa_status_t HSA_API HSA_DEPRECATED hsa_code_object_iterate_symbols( + hsa_code_object_t code_object, + hsa_status_t (*callback)(hsa_code_object_t code_object, + hsa_code_symbol_t symbol, + void *data), + void *data); /** @} */ diff --git a/runtime/hsa-runtime/inc/hsa_api_trace.h b/runtime/hsa-runtime/inc/hsa_api_trace.h index 40d443de1d..e3fd770b17 100644 --- a/runtime/hsa-runtime/inc/hsa_api_trace.h +++ b/runtime/hsa-runtime/inc/hsa_api_trace.h @@ -145,102 +145,281 @@ struct AmdExtTable { // Table to export HSA Core Runtime Apis struct CoreApiTable { ApiTableVersion version; - decltype(hsa_init)* hsa_init_fn; - decltype(hsa_shut_down)* hsa_shut_down_fn; - decltype(hsa_system_get_info)* hsa_system_get_info_fn; - decltype(hsa_system_extension_supported)* hsa_system_extension_supported_fn; - decltype(hsa_system_get_extension_table)* hsa_system_get_extension_table_fn; - decltype(hsa_iterate_agents)* hsa_iterate_agents_fn; - decltype(hsa_agent_get_info)* hsa_agent_get_info_fn; - decltype(hsa_queue_create)* hsa_queue_create_fn; - decltype(hsa_soft_queue_create)* hsa_soft_queue_create_fn; - decltype(hsa_queue_destroy)* hsa_queue_destroy_fn; - decltype(hsa_queue_inactivate)* hsa_queue_inactivate_fn; - decltype(hsa_queue_load_read_index_acquire)* hsa_queue_load_read_index_acquire_fn; - decltype(hsa_queue_load_read_index_relaxed)* hsa_queue_load_read_index_relaxed_fn; - decltype(hsa_queue_load_write_index_acquire)* hsa_queue_load_write_index_acquire_fn; - decltype(hsa_queue_load_write_index_relaxed)* hsa_queue_load_write_index_relaxed_fn; - decltype(hsa_queue_store_write_index_relaxed)* hsa_queue_store_write_index_relaxed_fn; - decltype(hsa_queue_store_write_index_release)* hsa_queue_store_write_index_release_fn; - decltype(hsa_queue_cas_write_index_acq_rel)* hsa_queue_cas_write_index_acq_rel_fn; - decltype(hsa_queue_cas_write_index_acquire)* hsa_queue_cas_write_index_acquire_fn; - decltype(hsa_queue_cas_write_index_relaxed)* hsa_queue_cas_write_index_relaxed_fn; - decltype(hsa_queue_cas_write_index_release)* hsa_queue_cas_write_index_release_fn; - decltype(hsa_queue_add_write_index_acq_rel)* hsa_queue_add_write_index_acq_rel_fn; - decltype(hsa_queue_add_write_index_acquire)* hsa_queue_add_write_index_acquire_fn; - decltype(hsa_queue_add_write_index_relaxed)* hsa_queue_add_write_index_relaxed_fn; - decltype(hsa_queue_add_write_index_release)* hsa_queue_add_write_index_release_fn; - decltype(hsa_queue_store_read_index_relaxed)* hsa_queue_store_read_index_relaxed_fn; - decltype(hsa_queue_store_read_index_release)* hsa_queue_store_read_index_release_fn; - decltype(hsa_agent_iterate_regions)* hsa_agent_iterate_regions_fn; - decltype(hsa_region_get_info)* hsa_region_get_info_fn; - decltype(hsa_agent_get_exception_policies)* hsa_agent_get_exception_policies_fn; - decltype(hsa_agent_extension_supported)* hsa_agent_extension_supported_fn; - decltype(hsa_memory_register)* hsa_memory_register_fn; - decltype(hsa_memory_deregister)* hsa_memory_deregister_fn; - decltype(hsa_memory_allocate)* hsa_memory_allocate_fn; - decltype(hsa_memory_free)* hsa_memory_free_fn; - decltype(hsa_memory_copy)* hsa_memory_copy_fn; - decltype(hsa_memory_assign_agent)* hsa_memory_assign_agent_fn; - decltype(hsa_signal_create)* hsa_signal_create_fn; - decltype(hsa_signal_destroy)* hsa_signal_destroy_fn; - decltype(hsa_signal_load_relaxed)* hsa_signal_load_relaxed_fn; - decltype(hsa_signal_load_acquire)* hsa_signal_load_acquire_fn; - decltype(hsa_signal_store_relaxed)* hsa_signal_store_relaxed_fn; - decltype(hsa_signal_store_release)* hsa_signal_store_release_fn; - decltype(hsa_signal_wait_relaxed)* hsa_signal_wait_relaxed_fn; - decltype(hsa_signal_wait_acquire)* hsa_signal_wait_acquire_fn; - decltype(hsa_signal_and_relaxed)* hsa_signal_and_relaxed_fn; - decltype(hsa_signal_and_acquire)* hsa_signal_and_acquire_fn; - decltype(hsa_signal_and_release)* hsa_signal_and_release_fn; - decltype(hsa_signal_and_acq_rel)* hsa_signal_and_acq_rel_fn; - decltype(hsa_signal_or_relaxed)* hsa_signal_or_relaxed_fn; - decltype(hsa_signal_or_acquire)* hsa_signal_or_acquire_fn; - decltype(hsa_signal_or_release)* hsa_signal_or_release_fn; - decltype(hsa_signal_or_acq_rel)* hsa_signal_or_acq_rel_fn; - decltype(hsa_signal_xor_relaxed)* hsa_signal_xor_relaxed_fn; - decltype(hsa_signal_xor_acquire)* hsa_signal_xor_acquire_fn; - decltype(hsa_signal_xor_release)* hsa_signal_xor_release_fn; - decltype(hsa_signal_xor_acq_rel)* hsa_signal_xor_acq_rel_fn; - decltype(hsa_signal_exchange_relaxed)* hsa_signal_exchange_relaxed_fn; - decltype(hsa_signal_exchange_acquire)* hsa_signal_exchange_acquire_fn; - decltype(hsa_signal_exchange_release)* hsa_signal_exchange_release_fn; - decltype(hsa_signal_exchange_acq_rel)* hsa_signal_exchange_acq_rel_fn; - decltype(hsa_signal_add_relaxed)* hsa_signal_add_relaxed_fn; - decltype(hsa_signal_add_acquire)* hsa_signal_add_acquire_fn; - decltype(hsa_signal_add_release)* hsa_signal_add_release_fn; - decltype(hsa_signal_add_acq_rel)* hsa_signal_add_acq_rel_fn; - decltype(hsa_signal_subtract_relaxed)* hsa_signal_subtract_relaxed_fn; - decltype(hsa_signal_subtract_acquire)* hsa_signal_subtract_acquire_fn; - decltype(hsa_signal_subtract_release)* hsa_signal_subtract_release_fn; - decltype(hsa_signal_subtract_acq_rel)* hsa_signal_subtract_acq_rel_fn; - decltype(hsa_signal_cas_relaxed)* hsa_signal_cas_relaxed_fn; - decltype(hsa_signal_cas_acquire)* hsa_signal_cas_acquire_fn; - decltype(hsa_signal_cas_release)* hsa_signal_cas_release_fn; - decltype(hsa_signal_cas_acq_rel)* hsa_signal_cas_acq_rel_fn; - decltype(hsa_isa_from_name)* hsa_isa_from_name_fn; - decltype(hsa_isa_get_info)* hsa_isa_get_info_fn; - decltype(hsa_isa_compatible)* hsa_isa_compatible_fn; - decltype(hsa_code_object_serialize)* hsa_code_object_serialize_fn; - decltype(hsa_code_object_deserialize)* hsa_code_object_deserialize_fn; - decltype(hsa_code_object_destroy)* hsa_code_object_destroy_fn; - decltype(hsa_code_object_get_info)* hsa_code_object_get_info_fn; - decltype(hsa_code_object_get_symbol)* hsa_code_object_get_symbol_fn; - decltype(hsa_code_symbol_get_info)* hsa_code_symbol_get_info_fn; - decltype(hsa_code_object_iterate_symbols)* hsa_code_object_iterate_symbols_fn; - decltype(hsa_executable_create)* hsa_executable_create_fn; - decltype(hsa_executable_destroy)* hsa_executable_destroy_fn; - decltype(hsa_executable_load_code_object)* hsa_executable_load_code_object_fn; - decltype(hsa_executable_freeze)* hsa_executable_freeze_fn; - decltype(hsa_executable_get_info)* hsa_executable_get_info_fn; - decltype(hsa_executable_global_variable_define)* hsa_executable_global_variable_define_fn; - decltype(hsa_executable_agent_global_variable_define)* hsa_executable_agent_global_variable_define_fn; - decltype(hsa_executable_readonly_variable_define)* hsa_executable_readonly_variable_define_fn; - decltype(hsa_executable_validate)* hsa_executable_validate_fn; - decltype(hsa_executable_get_symbol)* hsa_executable_get_symbol_fn; - decltype(hsa_executable_symbol_get_info)* hsa_executable_symbol_get_info_fn; - decltype(hsa_executable_iterate_symbols)* hsa_executable_iterate_symbols_fn; - decltype(hsa_status_string)* hsa_status_string_fn; + decltype(hsa_init)* hsa_init_fn; + decltype(hsa_shut_down)* hsa_shut_down_fn; + decltype(hsa_system_get_info)* hsa_system_get_info_fn; + decltype(hsa_system_extension_supported)* hsa_system_extension_supported_fn; + decltype(hsa_system_get_extension_table)* hsa_system_get_extension_table_fn; + decltype(hsa_iterate_agents)* hsa_iterate_agents_fn; + decltype(hsa_agent_get_info)* hsa_agent_get_info_fn; + decltype(hsa_queue_create)* hsa_queue_create_fn; + decltype(hsa_soft_queue_create)* hsa_soft_queue_create_fn; + decltype(hsa_queue_destroy)* hsa_queue_destroy_fn; + decltype(hsa_queue_inactivate)* hsa_queue_inactivate_fn; + union { + decltype(hsa_queue_load_read_index_scacquire)* hsa_queue_load_read_index_scacquire_fn; + decltype(hsa_queue_load_read_index_acquire)* hsa_queue_load_read_index_acquire_fn; + }; + decltype(hsa_queue_load_read_index_relaxed)* hsa_queue_load_read_index_relaxed_fn; + union { + decltype(hsa_queue_load_write_index_scacquire)* hsa_queue_load_write_index_scacquire_fn; + decltype(hsa_queue_load_write_index_acquire)* hsa_queue_load_write_index_acquire_fn; + }; + decltype(hsa_queue_load_write_index_relaxed)* hsa_queue_load_write_index_relaxed_fn; + decltype(hsa_queue_store_write_index_relaxed)* hsa_queue_store_write_index_relaxed_fn; + union { + decltype(hsa_queue_store_write_index_screlease)* hsa_queue_store_write_index_screlease_fn; + decltype(hsa_queue_store_write_index_release)* hsa_queue_store_write_index_release_fn; + }; + union { + decltype(hsa_queue_cas_write_index_scacq_screl)* hsa_queue_cas_write_index_scacq_screl_fn; + decltype(hsa_queue_cas_write_index_acq_rel)* hsa_queue_cas_write_index_acq_rel_fn; + }; + union { + decltype(hsa_queue_cas_write_index_scacquire)* hsa_queue_cas_write_index_scacquire_fn; + decltype(hsa_queue_cas_write_index_acquire)* hsa_queue_cas_write_index_acquire_fn; + }; + decltype(hsa_queue_cas_write_index_relaxed)* hsa_queue_cas_write_index_relaxed_fn; + union { + decltype(hsa_queue_cas_write_index_screlease)* hsa_queue_cas_write_index_screlease_fn; + decltype(hsa_queue_cas_write_index_release)* hsa_queue_cas_write_index_release_fn; + }; + union { + decltype(hsa_queue_add_write_index_scacq_screl)* hsa_queue_add_write_index_scacq_screl_fn; + decltype(hsa_queue_add_write_index_acq_rel)* hsa_queue_add_write_index_acq_rel_fn; + }; + union { + decltype(hsa_queue_add_write_index_scacquire)* hsa_queue_add_write_index_scacquire_fn; + decltype(hsa_queue_add_write_index_acquire)* hsa_queue_add_write_index_acquire_fn; + }; + decltype(hsa_queue_add_write_index_relaxed)* hsa_queue_add_write_index_relaxed_fn; + union { + decltype(hsa_queue_add_write_index_screlease)* hsa_queue_add_write_index_screlease_fn; + decltype(hsa_queue_add_write_index_release)* hsa_queue_add_write_index_release_fn; + }; + decltype(hsa_queue_store_read_index_relaxed)* hsa_queue_store_read_index_relaxed_fn; + union { + decltype(hsa_queue_store_read_index_screlease)* hsa_queue_store_read_index_screlease_fn; + decltype(hsa_queue_store_read_index_release)* hsa_queue_store_read_index_release_fn; + }; + decltype(hsa_agent_iterate_regions)* hsa_agent_iterate_regions_fn; + decltype(hsa_region_get_info)* hsa_region_get_info_fn; + decltype(hsa_agent_get_exception_policies)* hsa_agent_get_exception_policies_fn; + decltype(hsa_agent_extension_supported)* hsa_agent_extension_supported_fn; + decltype(hsa_memory_register)* hsa_memory_register_fn; + decltype(hsa_memory_deregister)* hsa_memory_deregister_fn; + decltype(hsa_memory_allocate)* hsa_memory_allocate_fn; + decltype(hsa_memory_free)* hsa_memory_free_fn; + decltype(hsa_memory_copy)* hsa_memory_copy_fn; + decltype(hsa_memory_assign_agent)* hsa_memory_assign_agent_fn; + decltype(hsa_signal_create)* hsa_signal_create_fn; + decltype(hsa_signal_destroy)* hsa_signal_destroy_fn; + decltype(hsa_signal_load_relaxed)* hsa_signal_load_relaxed_fn; + union { + decltype(hsa_signal_load_scacquire)* hsa_signal_load_scacquire_fn; + decltype(hsa_signal_load_acquire)* hsa_signal_load_acquire_fn; + }; + decltype(hsa_signal_store_relaxed)* hsa_signal_store_relaxed_fn; + union { + decltype(hsa_signal_store_screlease)* hsa_signal_store_screlease_fn; + decltype(hsa_signal_store_release)* hsa_signal_store_release_fn; + }; + decltype(hsa_signal_wait_relaxed)* hsa_signal_wait_relaxed_fn; + union { + decltype(hsa_signal_wait_scacquire)* hsa_signal_wait_scacquire_fn; + decltype(hsa_signal_wait_acquire)* hsa_signal_wait_acquire_fn; + }; + decltype(hsa_signal_and_relaxed)* hsa_signal_and_relaxed_fn; + union { + decltype(hsa_signal_and_scacquire)* hsa_signal_and_scacquire_fn; + decltype(hsa_signal_and_acquire)* hsa_signal_and_acquire_fn; + }; + union { + decltype(hsa_signal_and_screlease)* hsa_signal_and_screlease_fn; + decltype(hsa_signal_and_release)* hsa_signal_and_release_fn; + }; + union { + decltype(hsa_signal_and_scacq_screl)* hsa_signal_and_scacq_screl_fn; + decltype(hsa_signal_and_acq_rel)* hsa_signal_and_acq_rel_fn; + }; + decltype(hsa_signal_or_relaxed)* hsa_signal_or_relaxed_fn; + union { + decltype(hsa_signal_or_scacquire)* hsa_signal_or_scacquire_fn; + decltype(hsa_signal_or_acquire)* hsa_signal_or_acquire_fn; + }; + union { + decltype(hsa_signal_or_screlease)* hsa_signal_or_screlease_fn; + decltype(hsa_signal_or_release)* hsa_signal_or_release_fn; + }; + union { + decltype(hsa_signal_or_scacq_screl)* hsa_signal_or_scacq_screl_fn; + decltype(hsa_signal_or_acq_rel)* hsa_signal_or_acq_rel_fn; + }; + decltype(hsa_signal_xor_relaxed)* hsa_signal_xor_relaxed_fn; + union { + decltype(hsa_signal_xor_scacquire)* hsa_signal_xor_scacquire_fn; + decltype(hsa_signal_xor_acquire)* hsa_signal_xor_acquire_fn; + }; + union { + decltype(hsa_signal_xor_screlease)* hsa_signal_xor_screlease_fn; + decltype(hsa_signal_xor_release)* hsa_signal_xor_release_fn; + }; + union { + decltype(hsa_signal_xor_scacq_screl)* hsa_signal_xor_scacq_screl_fn; + decltype(hsa_signal_xor_acq_rel)* hsa_signal_xor_acq_rel_fn; + }; + decltype(hsa_signal_exchange_relaxed)* hsa_signal_exchange_relaxed_fn; + union { + decltype(hsa_signal_exchange_scacquire)* hsa_signal_exchange_scacquire_fn; + decltype(hsa_signal_exchange_acquire)* hsa_signal_exchange_acquire_fn; + }; + union { + decltype(hsa_signal_exchange_screlease)* hsa_signal_exchange_screlease_fn; + decltype(hsa_signal_exchange_release)* hsa_signal_exchange_release_fn; + }; + union { + decltype(hsa_signal_exchange_scacq_screl)* hsa_signal_exchange_scacq_screl_fn; + decltype(hsa_signal_exchange_acq_rel)* hsa_signal_exchange_acq_rel_fn; + }; + decltype(hsa_signal_add_relaxed)* hsa_signal_add_relaxed_fn; + union { + decltype(hsa_signal_add_scacquire)* hsa_signal_add_scacquire_fn; + decltype(hsa_signal_add_acquire)* hsa_signal_add_acquire_fn; + }; + union { + decltype(hsa_signal_add_screlease)* hsa_signal_add_screlease_fn; + decltype(hsa_signal_add_release)* hsa_signal_add_release_fn; + }; + union { + decltype(hsa_signal_add_scacq_screl)* hsa_signal_add_scacq_screl_fn; + decltype(hsa_signal_add_acq_rel)* hsa_signal_add_acq_rel_fn; + }; + decltype(hsa_signal_subtract_relaxed)* hsa_signal_subtract_relaxed_fn; + union { + decltype(hsa_signal_subtract_scacquire)* hsa_signal_subtract_scacquire_fn; + decltype(hsa_signal_subtract_acquire)* hsa_signal_subtract_acquire_fn; + }; + union { + decltype(hsa_signal_subtract_screlease)* hsa_signal_subtract_screlease_fn; + decltype(hsa_signal_subtract_release)* hsa_signal_subtract_release_fn; + }; + union { + decltype(hsa_signal_subtract_scacq_screl)* hsa_signal_subtract_scacq_screl_fn; + decltype(hsa_signal_subtract_acq_rel)* hsa_signal_subtract_acq_rel_fn; + }; + decltype(hsa_signal_cas_relaxed)* hsa_signal_cas_relaxed_fn; + union { + decltype(hsa_signal_cas_scacquire)* hsa_signal_cas_scacquire_fn; + decltype(hsa_signal_cas_acquire)* hsa_signal_cas_acquire_fn; + }; + union { + decltype(hsa_signal_cas_screlease)* hsa_signal_cas_screlease_fn; + decltype(hsa_signal_cas_release)* hsa_signal_cas_release_fn; + }; + union { + decltype(hsa_signal_cas_scacq_screl)* hsa_signal_cas_scacq_screl_fn; + decltype(hsa_signal_cas_acq_rel)* hsa_signal_cas_acq_rel_fn; + }; + + //===--- Instruction Set Architecture -----------------------------------===// + + decltype(hsa_isa_from_name)* hsa_isa_from_name_fn; + // Deprecated since v1.1. + decltype(hsa_isa_get_info)* hsa_isa_get_info_fn; + // Deprecated since v1.1. + decltype(hsa_isa_compatible)* hsa_isa_compatible_fn; + + //===--- Code Objects (deprecated) --------------------------------------===// + + // Deprecated since v1.1. + decltype(hsa_code_object_serialize)* hsa_code_object_serialize_fn; + // Deprecated since v1.1. + decltype(hsa_code_object_deserialize)* hsa_code_object_deserialize_fn; + // Deprecated since v1.1. + decltype(hsa_code_object_destroy)* hsa_code_object_destroy_fn; + // Deprecated since v1.1. + decltype(hsa_code_object_get_info)* hsa_code_object_get_info_fn; + // Deprecated since v1.1. + decltype(hsa_code_object_get_symbol)* hsa_code_object_get_symbol_fn; + // Deprecated since v1.1. + decltype(hsa_code_symbol_get_info)* hsa_code_symbol_get_info_fn; + // Deprecated since v1.1. + decltype(hsa_code_object_iterate_symbols)* hsa_code_object_iterate_symbols_fn; + + //===--- Executable -----------------------------------------------------===// + + // Deprecated since v1.1. + decltype(hsa_executable_create)* hsa_executable_create_fn; + decltype(hsa_executable_destroy)* hsa_executable_destroy_fn; + // Deprecated since v1.1. + decltype(hsa_executable_load_code_object)* hsa_executable_load_code_object_fn; + decltype(hsa_executable_freeze)* hsa_executable_freeze_fn; + decltype(hsa_executable_get_info)* hsa_executable_get_info_fn; + decltype(hsa_executable_global_variable_define)* + hsa_executable_global_variable_define_fn; + decltype(hsa_executable_agent_global_variable_define)* + hsa_executable_agent_global_variable_define_fn; + decltype(hsa_executable_readonly_variable_define)* + hsa_executable_readonly_variable_define_fn; + decltype(hsa_executable_validate)* hsa_executable_validate_fn; + // Deprecated since v1.1. + decltype(hsa_executable_get_symbol)* hsa_executable_get_symbol_fn; + decltype(hsa_executable_symbol_get_info)* hsa_executable_symbol_get_info_fn; + // Deprecated since v1.1. + decltype(hsa_executable_iterate_symbols)* hsa_executable_iterate_symbols_fn; + + //===--- Runtime Notifications ------------------------------------------===// + + decltype(hsa_status_string)* hsa_status_string_fn; + + //Start HSA v1.1 additions + decltype(hsa_extension_get_name)* hsa_extension_get_name_fn; + decltype(hsa_system_major_extension_supported)* hsa_system_major_extension_supported_fn; + decltype(hsa_system_get_major_extension_table)* hsa_system_get_major_extension_table_fn; + decltype(hsa_agent_major_extension_supported)* hsa_agent_major_extension_supported_fn; + decltype(hsa_cache_get_info)* hsa_cache_get_info_fn; + decltype(hsa_agent_iterate_caches)* hsa_agent_iterate_caches_fn; + decltype(hsa_signal_silent_store_relaxed)* hsa_signal_silent_store_relaxed_fn; + decltype(hsa_signal_silent_store_screlease)* hsa_signal_silent_store_screlease_fn; + decltype(hsa_signal_group_create)* hsa_signal_group_create_fn; + decltype(hsa_signal_group_destroy)* hsa_signal_group_destroy_fn; + decltype(hsa_signal_group_wait_any_scacquire)* hsa_signal_group_wait_any_scacquire_fn; + decltype(hsa_signal_group_wait_any_relaxed)* hsa_signal_group_wait_any_relaxed_fn; + + //===--- Instruction Set Architecture - HSA v1.1 additions --------------===// + + decltype(hsa_agent_iterate_isas)* hsa_agent_iterate_isas_fn; + decltype(hsa_isa_get_info_alt)* hsa_isa_get_info_alt_fn; + decltype(hsa_isa_get_exception_policies)* hsa_isa_get_exception_policies_fn; + decltype(hsa_isa_get_round_method)* hsa_isa_get_round_method_fn; + decltype(hsa_wavefront_get_info)* hsa_wavefront_get_info_fn; + decltype(hsa_isa_iterate_wavefronts)* hsa_isa_iterate_wavefronts_fn; + + //===--- Code Objects (deprecated) - HSA v1.1 additions -----------------===// + + // Deprecated since v1.1. + decltype(hsa_code_object_get_symbol_from_name)* + hsa_code_object_get_symbol_from_name_fn; + + //===--- Executable - HSA v1.1 additions --------------------------------===// + + decltype(hsa_code_object_reader_create_from_file)* + hsa_code_object_reader_create_from_file_fn; + decltype(hsa_code_object_reader_create_from_memory)* + hsa_code_object_reader_create_from_memory_fn; + decltype(hsa_code_object_reader_destroy)* hsa_code_object_reader_destroy_fn; + decltype(hsa_executable_create_alt)* hsa_executable_create_alt_fn; + decltype(hsa_executable_load_program_code_object)* + hsa_executable_load_program_code_object_fn; + decltype(hsa_executable_load_agent_code_object)* + hsa_executable_load_agent_code_object_fn; + decltype(hsa_executable_validate_alt)* hsa_executable_validate_alt_fn; + decltype(hsa_executable_get_symbol_by_name)* + hsa_executable_get_symbol_by_name_fn; + decltype(hsa_executable_iterate_agent_symbols)* + hsa_executable_iterate_agent_symbols_fn; + decltype(hsa_executable_iterate_program_symbols)* + hsa_executable_iterate_program_symbols_fn; }; // Table to export HSA Apis from Core Runtime, Amd Extensions diff --git a/runtime/hsa-runtime/inc/hsa_ext_image.h b/runtime/hsa-runtime/inc/hsa_ext_image.h index cd96af2904..999a32367b 100644 --- a/runtime/hsa-runtime/inc/hsa_ext_image.h +++ b/runtime/hsa-runtime/inc/hsa_ext_image.h @@ -710,6 +710,11 @@ typedef enum { } hsa_ext_sampler_addressing_mode_t; +/** + *@brief Fixed size container for address mode. + */ +typedef uint32_t hsa_ext_sampler_addressing_mode32_t; + /** * @brief Sampler coordinate modes. The enumeration values match the BRIG * BRIG_SAMPLER_COORD bit in BrigSamplerModifier. @@ -727,6 +732,11 @@ typedef enum { } hsa_ext_sampler_coordinate_mode_t; +/** + *@brief Fixed size container for coordinate mode. + */ +typedef uint32_t hsa_ext_sampler_coordinate_mode32_t; + /** * @brief Sampler filter modes. The enumeration values match the BRIG type * BrigSamplerFilter. @@ -747,6 +757,11 @@ typedef enum { } hsa_ext_sampler_filter_mode_t; +/** + *@brief Fixed size container for filter mode. + */ +typedef uint32_t hsa_ext_sampler_filter_mode32_t; + /** * @brief Implementation-independent sampler descriptor. */ @@ -754,18 +769,18 @@ typedef struct hsa_ext_sampler_descriptor_s { /** * Sampler coordinate mode describes the normalization of image coordinates. */ - hsa_ext_sampler_coordinate_mode_t coordinate_mode; + hsa_ext_sampler_coordinate_mode32_t coordinate_mode; /** * Sampler filter type describes the type of sampling performed. */ - hsa_ext_sampler_filter_mode_t filter_mode; + hsa_ext_sampler_filter_mode32_t filter_mode; /** * Sampler address mode describes the processing of out-of-range image * coordinates. */ - hsa_ext_sampler_addressing_mode_t address_mode; + hsa_ext_sampler_addressing_mode32_t address_mode; } hsa_ext_sampler_descriptor_t; @@ -828,7 +843,15 @@ enum { /** * Image size is not supported. */ - HSA_EXT_STATUS_ERROR_IMAGE_SIZE_UNSUPPORTED = 0x3001 + HSA_EXT_STATUS_ERROR_IMAGE_SIZE_UNSUPPORTED = 0x3001, + /** + * Image pitch is not supported or invalid. + */ + HSA_EXT_STATUS_ERROR_IMAGE_PITCH_UNSUPPORTED = 0x3002, + /** + * Sampler descriptor is not supported or invalid. + */ + HSA_EXT_STATUS_ERROR_SAMPLER_DESCRIPTOR_UNSUPPORTED = 0x3003 }; /** diff --git a/runtime/hsa-runtime/loader/executable.cpp b/runtime/hsa-runtime/loader/executable.cpp index 17eb7c1ca9..ea457c1c7c 100644 --- a/runtime/hsa-runtime/loader/executable.cpp +++ b/runtime/hsa-runtime/loader/executable.cpp @@ -135,11 +135,11 @@ void Loader::Destroy(Loader *loader) } Executable* AmdHsaCodeLoader::CreateExecutable( - hsa_profile_t profile, const char *options) + hsa_profile_t profile, const char *options, hsa_default_float_rounding_mode_t default_float_rounding_mode) { WriterLockGuard writer_lock(rw_lock_); - executables.push_back(new ExecutableImpl(profile, context, executables.size())); + executables.push_back(new ExecutableImpl(profile, context, executables.size(), default_float_rounding_mode)); return executables.back(); } @@ -372,6 +372,10 @@ bool SymbolImpl::GetInfo(hsa_symbol_info32_t symbol_info, void *value) { *((bool*)value) = is_definition; break; } + case HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_CALL_CONVENTION: { + *((uint32_t*)value) = 0; + break; + } case HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_OBJECT: case HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_ADDRESS: { if (!is_loaded) { @@ -525,15 +529,15 @@ bool VariableSymbol::GetInfo(hsa_symbol_info32_t symbol_info, void *value) { return true; } -bool LoadedCodeObjectImpl::GetInfo(amd_loaded_code_object_info_t attribute, void *value) +bool LoadedCodeObjectImpl::GetInfo(hsa_loaded_code_object_info_t attribute, void *value) { assert(value); switch (attribute) { - case AMD_LOADED_CODE_OBJECT_INFO_ELF_IMAGE: + case HSA_LOADED_CODE_OBJECT_INFO_ELF_IMAGE: ((hsa_code_object_t*)value)->handle = reinterpret_cast(elf_data); break; - case AMD_LOADED_CODE_OBJECT_INFO_ELF_IMAGE_SIZE: + case HSA_LOADED_CODE_OBJECT_INFO_ELF_IMAGE_SIZE: *((size_t*)value) = elf_size; break; default: { @@ -646,11 +650,16 @@ void Segment::Destroy() // ExecutableImpl. // //===----------------------------------------------------------------------===// -ExecutableImpl::ExecutableImpl(const hsa_profile_t &_profile, Context *context, size_t id) +ExecutableImpl::ExecutableImpl( + const hsa_profile_t &_profile, + Context *context, + size_t id, + hsa_default_float_rounding_mode_t default_float_rounding_mode) : Executable() , profile_(_profile) , context_(context) , id_(id) + , default_float_rounding_mode_(default_float_rounding_mode) , state_(HSA_EXECUTABLE_STATE_UNFROZEN) , program_allocation_segment(nullptr) { @@ -676,7 +685,6 @@ hsa_status_t ExecutableImpl::DefineProgramExternalVariable( { WriterLockGuard writer_lock(rw_lock_); assert(name); - assert(address); if (HSA_EXECUTABLE_STATE_FROZEN == state_) { return HSA_STATUS_ERROR_FROZEN_EXECUTABLE; @@ -711,7 +719,6 @@ hsa_status_t ExecutableImpl::DefineAgentExternalVariable( { WriterLockGuard writer_lock(rw_lock_); assert(name); - assert(address); if (HSA_EXECUTABLE_STATE_FROZEN == state_) { return HSA_STATUS_ERROR_FROZEN_EXECUTABLE; @@ -738,39 +745,41 @@ hsa_status_t ExecutableImpl::DefineAgentExternalVariable( return HSA_STATUS_SUCCESS; } +bool ExecutableImpl::IsProgramSymbol(const char *symbol_name) { + assert(symbol_name); + + ReaderLockGuard reader_lock(rw_lock_); + return program_symbols_.find(std::string(symbol_name)) != program_symbols_.end(); +} + Symbol* ExecutableImpl::GetSymbol( - const char *module_name, const char *symbol_name, - hsa_agent_t agent, - int32_t call_convention) + const hsa_agent_t *agent) { ReaderLockGuard reader_lock(rw_lock_); - return this->GetSymbolInternal(module_name, symbol_name, agent, call_convention); + return this->GetSymbolInternal(symbol_name, agent); } Symbol* ExecutableImpl::GetSymbolInternal( - const char *module_name, const char *symbol_name, - hsa_agent_t agent, - int32_t call_convention) + const hsa_agent_t *agent) { - assert(module_name); assert(symbol_name); std::string mangled_name = std::string(symbol_name); if (mangled_name.empty()) { return nullptr; } - if (!std::string(module_name).empty()) { - mangled_name.insert(0, "::"); - mangled_name.insert(0, std::string(module_name)); + + if (!agent) { + auto program_symbol = program_symbols_.find(mangled_name); + if (program_symbol != program_symbols_.end()) { + return program_symbol->second; + } + return nullptr; } - auto program_symbol = program_symbols_.find(mangled_name); - if (program_symbol != program_symbols_.end()) { - return program_symbol->second; - } - auto agent_symbol = agent_symbols_.find(std::make_pair(mangled_name, agent)); + auto agent_symbol = agent_symbols_.find(std::make_pair(mangled_name, *agent)); if (agent_symbol != agent_symbols_.end()) { return agent_symbol->second; } @@ -801,9 +810,54 @@ hsa_status_t ExecutableImpl::IterateSymbols( return HSA_STATUS_SUCCESS; } +hsa_status_t ExecutableImpl::IterateAgentSymbols( + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_agent_t agent, + hsa_executable_symbol_t symbol, + void *data), + void *data) { + ReaderLockGuard reader_lock(rw_lock_); + assert(callback); + + for (auto &symbol_entry : agent_symbols_) { + if (symbol_entry.second->GetAgent().handle != agent.handle) { + continue; + } + + hsa_status_t status = callback( + Executable::Handle(this), agent, Symbol::Handle(symbol_entry.second), + data); + if (status != HSA_STATUS_SUCCESS) { + return status; + } + } + + return HSA_STATUS_SUCCESS; +} + +hsa_status_t ExecutableImpl::IterateProgramSymbols( + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_executable_symbol_t symbol, + void *data), + void *data) { + ReaderLockGuard reader_lock(rw_lock_); + assert(callback); + + for (auto &symbol_entry : program_symbols_) { + hsa_status_t status = callback( + Executable::Handle(this), Symbol::Handle(symbol_entry.second), data); + if (status != HSA_STATUS_SUCCESS) { + return status; + } + } + + return HSA_STATUS_SUCCESS; +} + hsa_status_t ExecutableImpl::IterateLoadedCodeObjects( hsa_status_t (*callback)( - amd_loaded_code_object_t loaded_code_object, + hsa_loaded_code_object_t loaded_code_object, void *data), void *data) { @@ -908,6 +962,11 @@ hsa_status_t ExecutableImpl::GetInfo( *((hsa_executable_state_t*)value) = state_; break; } + case HSA_EXECUTABLE_INFO_DEFAULT_FLOAT_ROUNDING_MODE: { + *((hsa_default_float_rounding_mode_t*)value) = + default_float_rounding_mode_; + break; + } default: { return HSA_STATUS_ERROR_INVALID_ARGUMENT; } @@ -926,9 +985,10 @@ hsa_status_t ExecutableImpl::LoadCodeObject( hsa_agent_t agent, hsa_code_object_t code_object, const char *options, - amd_loaded_code_object_t *loaded_code_object) + hsa_loaded_code_object_t *loaded_code_object, + bool load_legacy) { - return LoadCodeObject(agent, code_object, 0, options, loaded_code_object); + return LoadCodeObject(agent, code_object, 0, options, loaded_code_object, load_legacy); } hsa_status_t ExecutableImpl::LoadCodeObject( @@ -936,7 +996,8 @@ hsa_status_t ExecutableImpl::LoadCodeObject( hsa_code_object_t code_object, size_t code_object_size, const char *options, - amd_loaded_code_object_t *loaded_code_object) + hsa_loaded_code_object_t *loaded_code_object, + bool load_legacy) { WriterLockGuard writer_lock(rw_lock_); if (HSA_EXECUTABLE_STATE_FROZEN == state_) { @@ -954,6 +1015,7 @@ hsa_status_t ExecutableImpl::LoadCodeObject( } code.reset(new code::AmdHsaCode()); + load_legacy_ = load_legacy; if (!code->InitAsHandle(code_object)) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; @@ -984,14 +1046,14 @@ hsa_status_t ExecutableImpl::LoadCodeObject( hsa_isa_t objectsIsa = context_->IsaFromName(codeIsa.c_str()); if (!objectsIsa.handle) { return HSA_STATUS_ERROR_INVALID_ISA_NAME; } - if (!context_->IsaSupportedByAgent(agent, objectsIsa)) { return HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS; } - uint32_t majorVersion, minorVersion; if (!code->GetNoteCodeObjectVersion(&majorVersion, &minorVersion)) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } if (majorVersion != 1 && majorVersion != 2) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } + if (agent.handle == 0 && majorVersion == 1) { return HSA_STATUS_ERROR_INVALID_AGENT; } + if (agent.handle != 0 && !context_->IsaSupportedByAgent(agent, objectsIsa)) { return HSA_STATUS_ERROR_INCOMPATIBLE_ARGUMENTS; } uint32_t codeHsailMajor; uint32_t codeHsailMinor; @@ -1084,7 +1146,11 @@ hsa_status_t ExecutableImpl::LoadSymbol(hsa_agent_t agent, code::Symbol* sym) hsa_status_t ExecutableImpl::LoadDefinitionSymbol(hsa_agent_t agent, code::Symbol* sym) { - if (sym->IsAgent()) { + bool isAgent = sym->IsAgent(); + if (!load_legacy_) { + isAgent = agent.handle == 0 ? false : true; + } + if (isAgent) { auto agent_symbol = agent_symbols_.find(std::make_pair(sym->Name(), agent)); if (agent_symbol != agent_symbols_.end()) { // TODO(spec): this is not spec compliant. @@ -1164,7 +1230,7 @@ hsa_status_t ExecutableImpl::LoadDefinitionSymbol(hsa_agent_t agent, code::Symbo return HSA_STATUS_ERROR; } assert(symbol); - if (sym->IsAgent()) { + if (isAgent) { agent_symbols_.insert(std::make_pair(std::make_pair(sym->Name(), agent), symbol)); } else { program_symbols_.insert(std::make_pair(sym->Name(), symbol)); @@ -1285,11 +1351,11 @@ hsa_status_t ExecutableImpl::ApplyStaticRelocation(hsa_agent_t agent, amd::hsa:: if (!addr) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } break; case STT_COMMON: { - hsa_agent_t sagent = agent; + hsa_agent_t *sagent = &agent; if (STA_AMDGPU_HSA_GLOBAL_PROGRAM == ELF64_ST_AMDGPU_ALLOCATION(sym->other())) { - sagent.handle = 0; + sagent = nullptr; } - SymbolImpl* esym = (SymbolImpl*) GetSymbolInternal("", sym->name().c_str(), sagent, 0); + SymbolImpl* esym = (SymbolImpl*) GetSymbolInternal(sym->name().c_str(), sagent); if (!esym) { return HSA_STATUS_ERROR_VARIABLE_UNDEFINED; } addr = esym->address; break; diff --git a/runtime/hsa-runtime/loader/executable.hpp b/runtime/hsa-runtime/loader/executable.hpp index 478a03ffdb..8f3c153077 100644 --- a/runtime/hsa-runtime/loader/executable.hpp +++ b/runtime/hsa-runtime/loader/executable.hpp @@ -94,6 +94,10 @@ public: uint64_t address; hsa_agent_t agent; + hsa_agent_t GetAgent() override { + return agent; + } + protected: SymbolImpl(const bool &_is_loaded, const hsa_symbol_kind_t &_kind, @@ -253,7 +257,7 @@ public: size_t ElfSize() const { return elf_size; } std::vector& LoadedSegments() { return loaded_segments; } - bool GetInfo(amd_loaded_code_object_info_t attribute, void *value) override; + bool GetInfo(hsa_loaded_code_object_info_t attribute, void *value) override; hsa_status_t IterateLoadedSegments( hsa_status_t (*callback)( @@ -349,7 +353,11 @@ public: return state_; } - ExecutableImpl(const hsa_profile_t &_profile, Context *context, size_t id); + ExecutableImpl( + const hsa_profile_t &_profile, + Context *context, + size_t id, + hsa_default_float_rounding_mode_t default_float_rounding_mode); ~ExecutableImpl(); @@ -368,14 +376,16 @@ public: hsa_agent_t agent, hsa_code_object_t code_object, const char *options, - amd_loaded_code_object_t *loaded_code_object); + hsa_loaded_code_object_t *loaded_code_object, + bool load_legacy = true); hsa_status_t LoadCodeObject( hsa_agent_t agent, hsa_code_object_t code_object, size_t code_object_size, const char *options, - amd_loaded_code_object_t *loaded_code_object); + hsa_loaded_code_object_t *loaded_code_object, + bool load_legacy = true); hsa_status_t Freeze(const char *options); @@ -386,18 +396,36 @@ public: return HSA_STATUS_SUCCESS; } + /// @note needed for hsa v1.0. + /// @todo remove during loader refactoring. + bool IsProgramSymbol(const char *symbol_name) override; + Symbol* GetSymbol( - const char *module_name, const char *symbol_name, - hsa_agent_t agent, - int32_t call_convention); + const hsa_agent_t *agent) override; hsa_status_t IterateSymbols( iterate_symbols_f callback, void *data); + /// @since hsa v1.1. + hsa_status_t IterateAgentSymbols( + hsa_agent_t agent, + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_agent_t agent, + hsa_executable_symbol_t symbol, + void *data), + void *data) override; + + /// @since hsa v1.1. + hsa_status_t IterateProgramSymbols( + hsa_status_t (*callback)(hsa_executable_t exec, + hsa_executable_symbol_t symbol, + void *data), + void *data) override; + hsa_status_t IterateLoadedCodeObjects( hsa_status_t (*callback)( - amd_loaded_code_object_t loaded_code_object, + hsa_loaded_code_object_t loaded_code_object, void *data), void *data); @@ -424,12 +452,11 @@ private: ExecutableImpl& operator=(const ExecutableImpl &e); std::unique_ptr code; + bool load_legacy_; Symbol* GetSymbolInternal( - const char *module_name, const char *symbol_name, - hsa_agent_t agent, - int32_t call_convention); + const hsa_agent_t *agent); hsa_status_t LoadSegment(hsa_agent_t agent, code::Segment* s, uint32_t majorVersion, uint16_t machine); hsa_status_t LoadSegmentV1(hsa_agent_t agent, amd::hsa::code::Segment* seg); @@ -454,6 +481,7 @@ private: hsa_profile_t profile_; Context *context_; const size_t id_; + hsa_default_float_rounding_mode_t default_float_rounding_mode_; hsa_executable_state_t state_; ProgramSymbolMap program_symbols_; @@ -475,7 +503,10 @@ public: Context* GetContext() const { return context; } - Executable* CreateExecutable(hsa_profile_t profile, const char *options) override; + Executable* CreateExecutable( + hsa_profile_t profile, + const char *options, + hsa_default_float_rounding_mode_t default_float_rounding_mode = HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT) override; void DestroyExecutable(Executable *executable) override;