From f6565a2f70779c8c737f6a3a590571be800c05b9 Mon Sep 17 00:00:00 2001 From: "Zhuravlyov, Konstantin (x21446) MA" Date: Thu, 24 Mar 2016 19:00:30 -0500 Subject: [PATCH] Clean up extensions and provide public extension/API to query host address given device address: - Partially remove 'amd_load_map' extension because it is not used and will not be used - Remove 'hsa_amd_query_kernel_host_address' API - Add 'hsa_ext_amd_loaded_code_object' extension - Add 'hsa_ext_amd_loaded_code_object_query_host_address' API - Most likely to be used by debugger, profiler, and hcc (printf) - Update affected sources - 'hsa_system_extension_supported' - 'hsa_system_get_extension_table' - SoftCP path - Integrate CLs 1250699, 1251204, 1251214 from stg sc ReviewBoardURL: http://ocltc.amd.com/reviews/r/10091/ Testing: smoke (ok), teamcity (ok), samples on fiji (AQL and SoftCP) (ok) [git-p4: depot-paths = "//depot/stg/hsa/drivers/hsa/runtime/": change = 1251223] --- runtime/hsa-runtime/core/CMakeLists.txt | 2 +- runtime/hsa-runtime/core/hsacore.so.def | 1 - .../hsa-runtime/core/inc/amd_hsa_loader.hpp | 25 ++- runtime/hsa-runtime/core/inc/amd_load_map.h | 174 ------------------ .../hsa-runtime/core/runtime/amd_load_map.cpp | 172 ----------------- .../core/runtime/amd_loader_context.cpp | 4 +- runtime/hsa-runtime/core/runtime/hsa.cpp | 30 +-- .../hsa-runtime/core/runtime/hsa_ext_amd.cpp | 10 - .../hsa_ven_amd_loaded_code_object.cpp | 71 +++++++ runtime/hsa-runtime/inc/hsa.h | 9 +- runtime/hsa-runtime/inc/hsa_ext_amd.h | 22 --- .../inc/hsa_ven_amd_loaded_code_object.h | 95 ++++++++++ 12 files changed, 218 insertions(+), 397 deletions(-) delete mode 100644 runtime/hsa-runtime/core/inc/amd_load_map.h delete mode 100644 runtime/hsa-runtime/core/runtime/amd_load_map.cpp create mode 100644 runtime/hsa-runtime/core/runtime/hsa_ven_amd_loaded_code_object.cpp create mode 100644 runtime/hsa-runtime/inc/hsa_ven_amd_loaded_code_object.h diff --git a/runtime/hsa-runtime/core/CMakeLists.txt b/runtime/hsa-runtime/core/CMakeLists.txt index 2ad9fbee52..7c59dbab4c 100644 --- a/runtime/hsa-runtime/core/CMakeLists.txt +++ b/runtime/hsa-runtime/core/CMakeLists.txt @@ -118,7 +118,7 @@ set ( CORE_SRCS ${CORE_SRCS} runtime/amd_cpu_agent.cpp ) set ( CORE_SRCS ${CORE_SRCS} runtime/amd_gpu_agent.cpp ) set ( CORE_SRCS ${CORE_SRCS} runtime/amd_aql_queue.cpp ) set ( CORE_SRCS ${CORE_SRCS} runtime/amd_loader_context.cpp ) -set ( CORE_SRCS ${CORE_SRCS} runtime/amd_load_map.cpp ) +set ( CORE_SRCS ${CORE_SRCS} runtime/hsa_ven_amd_loaded_code_object.cpp ) set ( CORE_SRCS ${CORE_SRCS} runtime/amd_memory_region.cpp ) set ( CORE_SRCS ${CORE_SRCS} runtime/amd_topology.cpp ) set ( CORE_SRCS ${CORE_SRCS} runtime/default_signal.cpp ) diff --git a/runtime/hsa-runtime/core/hsacore.so.def b/runtime/hsa-runtime/core/hsacore.so.def index 30b6061141..769809dc96 100644 --- a/runtime/hsa-runtime/core/hsacore.so.def +++ b/runtime/hsa-runtime/core/hsacore.so.def @@ -127,7 +127,6 @@ global: hsa_amd_interop_map_buffer; hsa_amd_interop_unmap_buffer; hsa_amd_image_create; - hsa_amd_query_kernel_host_address; hsa_ext_image_get_capability; hsa_ext_image_data_get_info; hsa_ext_image_create; diff --git a/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp b/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp index 6bcf763473..a23dcbc533 100644 --- a/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp +++ b/runtime/hsa-runtime/core/inc/amd_hsa_loader.hpp @@ -48,7 +48,6 @@ #include "hsa.h" #include "hsa_ext_image.h" #include "amd_hsa_elf.h" -#include "amd_load_map.h" #include #include #include @@ -73,6 +72,30 @@ 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 +}; + +/// @brief Loaded segment handle. +typedef struct amd_loaded_segment_s { + uint64_t handle; +} amd_loaded_segment_t; + +/// @brief Loaded segment attributes. +enum amd_loaded_segment_info_t { + AMD_LOADED_SEGMENT_INFO_TYPE = 0, + AMD_LOADED_SEGMENT_INFO_ELF_BASE_ADDRESS = 1, + AMD_LOADED_SEGMENT_INFO_LOAD_BASE_ADDRESS = 2, + AMD_LOADED_SEGMENT_INFO_SIZE = 3 +}; + namespace amd { namespace hsa { namespace loader { diff --git a/runtime/hsa-runtime/core/inc/amd_load_map.h b/runtime/hsa-runtime/core/inc/amd_load_map.h deleted file mode 100644 index 25967b1da2..0000000000 --- a/runtime/hsa-runtime/core/inc/amd_load_map.h +++ /dev/null @@ -1,174 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// 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 AMD_LOAD_MAP_H -#define AMD_LOAD_MAP_H - -#include "hsa.h" - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/// @todo. -enum { - AMD_EXTENSION_LOAD_MAP = 0x1002 -}; - -/// @todo. -typedef struct amd_loaded_code_object_s { - uint64_t handle; -} amd_loaded_code_object_t; - -/// @todo. -enum amd_loaded_code_object_info_t { - AMD_LOADED_CODE_OBJECT_INFO_ELF_IMAGE = 0, - AMD_LOADED_CODE_OBJECT_INFO_ELF_IMAGE_SIZE = 1 -}; - -/// @todo. -typedef struct amd_loaded_segment_s { - uint64_t handle; -} amd_loaded_segment_t; - -/// @todo. -enum amd_loaded_segment_info_t { - AMD_LOADED_SEGMENT_INFO_TYPE = 0, - AMD_LOADED_SEGMENT_INFO_ELF_BASE_ADDRESS = 1, - AMD_LOADED_SEGMENT_INFO_LOAD_BASE_ADDRESS = 2, - AMD_LOADED_SEGMENT_INFO_SIZE = 3 -}; - -/// @todo. -hsa_status_t amd_executable_load_code_object( - hsa_executable_t executable, - hsa_agent_t agent, - hsa_code_object_t code_object, - const char *options, - amd_loaded_code_object_t *loaded_code_object); - -/// @brief Invokes @p callback for each available executable in current -/// process. -hsa_status_t amd_iterate_executables( - hsa_status_t (*callback)( - hsa_executable_t executable, - void *data), - void *data); - -/// @brief Invokes @p callback for each loaded code object in specified -/// @p executable. -hsa_status_t amd_executable_iterate_loaded_code_objects( - hsa_executable_t executable, - hsa_status_t (*callback)( - amd_loaded_code_object_t loaded_code_object, - void *data), - void *data); - -/// @brief Retrieves current value of specified @p loaded_code_object's -/// @p attribute. -hsa_status_t amd_loaded_code_object_get_info( - amd_loaded_code_object_t loaded_code_object, - amd_loaded_code_object_info_t attribute, - void *value); - -/// @brief Invokes @p callback for each loaded segment in specified -/// @p loaded_code_object. -hsa_status_t amd_loaded_code_object_iterate_loaded_segments( - amd_loaded_code_object_t loaded_code_object, - hsa_status_t (*callback)( - amd_loaded_segment_t loaded_segment, - void *data), - void *data); - -/// @brief Retrieves current value of specified @p loaded_segment's -/// @p attribute. -hsa_status_t amd_loaded_segment_get_info( - amd_loaded_segment_t loaded_segment, - amd_loaded_segment_info_t attribute, - void *value); - -#define amd_load_map_1_00 - -typedef struct amd_load_map_1_00_pfn_s { - hsa_status_t (*amd_executable_load_code_object)( - hsa_executable_t executable, - hsa_agent_t agent, - hsa_code_object_t code_object, - const char *options, - amd_loaded_code_object_t *loaded_code_object); - - hsa_status_t (*amd_iterate_executables)( - hsa_status_t (*callback)( - hsa_executable_t executable, - void *data), - void *data); - - hsa_status_t (*amd_executable_iterate_loaded_code_objects)( - hsa_executable_t executable, - hsa_status_t (*callback)( - amd_loaded_code_object_t loaded_code_object, - void *data), - void *data); - - hsa_status_t (*amd_loaded_code_object_get_info)( - amd_loaded_code_object_t loaded_code_object, - amd_loaded_code_object_info_t attribute, - void *value); - - hsa_status_t (*amd_loaded_code_object_iterate_loaded_segments)( - amd_loaded_code_object_t loaded_code_object, - hsa_status_t (*callback)( - amd_loaded_segment_t loaded_segment, - void *data), - void *data); - - hsa_status_t (*amd_loaded_segment_get_info)( - amd_loaded_segment_t loaded_segment, - amd_loaded_segment_info_t attribute, - void *value); -} amd_load_map_1_00_pfn_t; - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif // AMD_LOAD_MAP_H diff --git a/runtime/hsa-runtime/core/runtime/amd_load_map.cpp b/runtime/hsa-runtime/core/runtime/amd_load_map.cpp deleted file mode 100644 index 7a71944801..0000000000 --- a/runtime/hsa-runtime/core/runtime/amd_load_map.cpp +++ /dev/null @@ -1,172 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// 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 -#include "core/inc/amd_hsa_loader.hpp" -#include "core/inc/amd_load_map.h" -#include "core/inc/runtime.h" - -using amd::hsa::loader::Executable; -using amd::hsa::loader::LoadedCodeObject; -using amd::hsa::loader::LoadedSegment; - -hsa_status_t amd_executable_load_code_object( - hsa_executable_t executable, - hsa_agent_t agent, - hsa_code_object_t code_object, - const char *options, - amd_loaded_code_object_t *loaded_code_object) -{ - if (!core::Runtime::runtime_singleton_->IsOpen()) { - return HSA_STATUS_ERROR_NOT_INITIALIZED; - } - if (nullptr == loaded_code_object) { - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - - Executable *exec = Executable::Object(executable); - if (nullptr == exec) { - return HSA_STATUS_ERROR_INVALID_EXECUTABLE; - } - return exec->LoadCodeObject(agent, code_object, options, loaded_code_object); -} - -hsa_status_t amd_iterate_executables( - hsa_status_t (*callback)( - hsa_executable_t executable, - void *data), - void *data) -{ - if (!core::Runtime::runtime_singleton_->IsOpen()) { - return HSA_STATUS_ERROR_NOT_INITIALIZED; - } - if (nullptr == callback) { - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - - return core::Runtime::runtime_singleton_->loader()->IterateExecutables(callback, data); -} - -hsa_status_t amd_executable_iterate_loaded_code_objects( - hsa_executable_t executable, - hsa_status_t (*callback)( - amd_loaded_code_object_t loaded_code_object, - void *data), - void *data) -{ - if (!core::Runtime::runtime_singleton_->IsOpen()) { - return HSA_STATUS_ERROR_NOT_INITIALIZED; - } - if (nullptr == callback) { - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - - Executable *exec = Executable::Object(executable); - if (nullptr == exec) { - return HSA_STATUS_ERROR_INVALID_EXECUTABLE; - } - return exec->IterateLoadedCodeObjects(callback, data); -} - -hsa_status_t amd_loaded_code_object_get_info( - amd_loaded_code_object_t loaded_code_object, - amd_loaded_code_object_info_t attribute, - void *value) -{ - if (!core::Runtime::runtime_singleton_->IsOpen()) { - return HSA_STATUS_ERROR_NOT_INITIALIZED; - } - if (nullptr == value) { - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - - LoadedCodeObject *obj = LoadedCodeObject::Object(loaded_code_object); - if (nullptr == obj) { - // \todo: new error code: AMD_STATUS_ERROR_INVALID_LOADED_CODE_OBJECT. - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - return false == obj->GetInfo(attribute, value) ? - HSA_STATUS_ERROR_INVALID_ARGUMENT : HSA_STATUS_SUCCESS; -} - -hsa_status_t amd_loaded_code_object_iterate_loaded_segments( - amd_loaded_code_object_t loaded_code_object, - hsa_status_t (*callback)( - amd_loaded_segment_t loaded_segment, - void *data), - void *data) -{ - if (!core::Runtime::runtime_singleton_->IsOpen()) { - return HSA_STATUS_ERROR_NOT_INITIALIZED; - } - if (nullptr == callback) { - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - - LoadedCodeObject *obj = LoadedCodeObject::Object(loaded_code_object); - if (nullptr == obj) { - // \todo: new error code: AMD_STATUS_ERROR_INVALID_LOADED_CODE_OBJECT. - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - return obj->IterateLoadedSegments(callback, data); -} - -hsa_status_t amd_loaded_segment_get_info( - amd_loaded_segment_t loaded_segment, - amd_loaded_segment_info_t attribute, - void *value) -{ - if (!core::Runtime::runtime_singleton_->IsOpen()) { - return HSA_STATUS_ERROR_NOT_INITIALIZED; - } - if (nullptr == value) { - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - - LoadedSegment *obj = LoadedSegment::Object(loaded_segment); - if (nullptr == obj) { - // \todo: new error code: AMD_STATUS_ERROR_INVALID_LOADED_SEGMENT. - return HSA_STATUS_ERROR_INVALID_ARGUMENT; - } - return false == obj->GetInfo(attribute, value) ? - HSA_STATUS_ERROR_INVALID_ARGUMENT : HSA_STATUS_SUCCESS; -} diff --git a/runtime/hsa-runtime/core/runtime/amd_loader_context.cpp b/runtime/hsa-runtime/core/runtime/amd_loader_context.cpp index 9e164df141..5d5f44c718 100644 --- a/runtime/hsa-runtime/core/runtime/amd_loader_context.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_loader_context.cpp @@ -108,7 +108,7 @@ public: void* Address(size_t offset = 0) const override { assert(this->Allocated()); return (char*)ptr_ + offset; } void* HostAddress(size_t offset = 0) const override - { return nullptr; } + { return this->Address(offset); } bool Allocated() const override { return nullptr != ptr_; } @@ -178,7 +178,7 @@ public: void* Address(size_t offset = 0) const override { assert(this->Allocated()); return (char*)ptr_ + offset; } void* HostAddress(size_t offset = 0) const override - { return nullptr; } + { return this->Address(offset); } bool Allocated() const override { return nullptr != ptr_; } diff --git a/runtime/hsa-runtime/core/runtime/hsa.cpp b/runtime/hsa-runtime/core/runtime/hsa.cpp index c6515475e2..bf48df4cb0 100644 --- a/runtime/hsa-runtime/core/runtime/hsa.cpp +++ b/runtime/hsa-runtime/core/runtime/hsa.cpp @@ -54,8 +54,8 @@ #include "core/inc/signal.h" #include "core/inc/default_signal.h" #include "core/inc/interrupt_signal.h" -#include "core/inc/amd_load_map.h" #include "core/inc/amd_loader_context.hpp" +#include "inc/hsa_ven_amd_loaded_code_object.h" using namespace amd::hsa::code; @@ -169,7 +169,8 @@ hsa_status_t IS_OPEN(); if ((extension > HSA_EXTENSION_AMD_PROFILER && - extension != AMD_EXTENSION_LOAD_MAP) || result == NULL) { + extension != HSA_EXTENSION_AMD_LOADED_CODE_OBJECT) || + (result == NULL)) { return HSA_STATUS_ERROR_INVALID_ARGUMENT; } @@ -244,16 +245,14 @@ hsa_status_t hsa_ext_program_iterate_modules; return HSA_STATUS_SUCCESS; - } else if (extension == AMD_EXTENSION_LOAD_MAP) { + } else if (extension == HSA_EXTENSION_AMD_LOADED_CODE_OBJECT) { // Currently there is only version 1.00. - amd_load_map_1_00_pfn_t* amd_table = - reinterpret_cast(table); - amd_table->amd_executable_load_code_object = amd_executable_load_code_object; - amd_table->amd_iterate_executables = amd_iterate_executables; - amd_table->amd_executable_iterate_loaded_code_objects = amd_executable_iterate_loaded_code_objects; - amd_table->amd_loaded_code_object_get_info = amd_loaded_code_object_get_info; - amd_table->amd_loaded_code_object_iterate_loaded_segments = amd_loaded_code_object_iterate_loaded_segments; - amd_table->amd_loaded_segment_get_info = amd_loaded_segment_get_info; + hsa_ven_amd_loaded_code_object_1_00_pfn_t* ext_table = + reinterpret_cast(table); + ext_table->hsa_ven_amd_loaded_code_object_query_host_address = + hsa_ven_amd_loaded_code_object_query_host_address; + + return HSA_STATUS_SUCCESS; } else { // TODO: other extensions are not yet implemented. return HSA_STATUS_ERROR; @@ -1401,9 +1400,14 @@ hsa_status_t hsa_agent_t agent, hsa_code_object_t code_object, const char* options) { + IS_OPEN(); + amd_loaded_code_object_t loaded_code_object = {0}; - return amd_executable_load_code_object( - executable, agent, code_object, options, &loaded_code_object); + amd::hsa::loader::Executable *exec = amd::hsa::loader::Executable::Object(executable); + if (!exec) { + return HSA_STATUS_ERROR_INVALID_EXECUTABLE; + } + return exec->LoadCodeObject(agent, code_object, options, &loaded_code_object); } hsa_status_t diff --git a/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp b/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp index bd12df0e4f..9394c30062 100644 --- a/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp +++ b/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp @@ -553,13 +553,3 @@ hsa_status_t hsa_amd_interop_unmap_buffer(void* ptr) { if (ptr != NULL) core::Runtime::runtime_singleton_->InteropUnmap(ptr); return HSA_STATUS_SUCCESS; } - -hsa_status_t HSA_API hsa_amd_query_kernel_host_address( - uint64_t kernel_device_address, - uint64_t *kernel_host_address) { - IS_OPEN(); - IS_BAD_PTR(kernel_host_address); - - *kernel_host_address = core::Runtime::runtime_singleton_->loader()->FindHostAddress(kernel_device_address); - return *kernel_host_address == 0 ? HSA_STATUS_ERROR_INVALID_ARGUMENT : HSA_STATUS_SUCCESS; -} diff --git a/runtime/hsa-runtime/core/runtime/hsa_ven_amd_loaded_code_object.cpp b/runtime/hsa-runtime/core/runtime/hsa_ven_amd_loaded_code_object.cpp new file mode 100644 index 0000000000..958e3051ee --- /dev/null +++ b/runtime/hsa-runtime/core/runtime/hsa_ven_amd_loaded_code_object.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 "hsa_ven_amd_loaded_code_object.h" + +#include "core/inc/amd_hsa_loader.hpp" +#include "core/inc/runtime.h" + +using namespace core; + +hsa_status_t hsa_ven_amd_loaded_code_object_query_host_address( + const void *device_address, + const void **host_address) { + if (false == core::Runtime::runtime_singleton_->IsOpen()) { + return HSA_STATUS_ERROR_NOT_INITIALIZED; + } + if (nullptr == device_address) { + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + if (nullptr == host_address) { + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + + uint64_t udaddr = reinterpret_cast(device_address); + uint64_t uhaddr = Runtime::runtime_singleton_->loader()->FindHostAddress(udaddr); + if (0 == uhaddr) { + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + + *host_address = reinterpret_cast(uhaddr); + return HSA_STATUS_SUCCESS; +} diff --git a/runtime/hsa-runtime/inc/hsa.h b/runtime/hsa-runtime/inc/hsa.h index 22b308fd45..f80768dbf1 100644 --- a/runtime/hsa-runtime/inc/hsa.h +++ b/runtime/hsa-runtime/inc/hsa.h @@ -457,7 +457,14 @@ typedef enum { * Images extension. */ HSA_EXTENSION_IMAGES = 1, - HSA_EXTENSION_AMD_PROFILER = 2 + /** + * Profiler extension. + */ + HSA_EXTENSION_AMD_PROFILER = 2, + /** + * Loaded code object extension. + */ + HSA_EXTENSION_AMD_LOADED_CODE_OBJECT = 3 } hsa_extension_t; /** diff --git a/runtime/hsa-runtime/inc/hsa_ext_amd.h b/runtime/hsa-runtime/inc/hsa_ext_amd.h index f55946c8e5..c00dc3939a 100644 --- a/runtime/hsa-runtime/inc/hsa_ext_amd.h +++ b/runtime/hsa-runtime/inc/hsa_ext_amd.h @@ -1176,28 +1176,6 @@ hsa_status_t HSA_API hsa_amd_image_create( hsa_ext_image_t *image ); -/** - * @brief Queries equivalent kernel host address given kernel device address. - * - * @param[in] kernel_device_address Kernel device address to query equivalent - * kernel host address for. - * - * @param[out] kernel_host_address Pointer to an application-allocated buffer - * where to store equivalend kernel host address. - * - * @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 kernel_device_address is - * invalid, or @p kernel_device_address is already a kernel host address, or - * @p kernel_host_address is NULL. - */ -hsa_status_t HSA_API hsa_amd_query_kernel_host_address( - uint64_t kernel_device_address, - uint64_t *kernel_host_address); - #ifdef __cplusplus } // end extern "C" block #endif diff --git a/runtime/hsa-runtime/inc/hsa_ven_amd_loaded_code_object.h b/runtime/hsa-runtime/inc/hsa_ven_amd_loaded_code_object.h new file mode 100644 index 0000000000..fe56e38136 --- /dev/null +++ b/runtime/hsa-runtime/inc/hsa_ven_amd_loaded_code_object.h @@ -0,0 +1,95 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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. +// +//////////////////////////////////////////////////////////////////////////////// + +// HSA AMD extension for loaded code objects. + +#ifndef HSA_VEN_AMD_LOADED_CODE_OBJECT_H +#define HSA_VEN_AMD_LOADED_CODE_OBJECT_H + +#include "hsa.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/** + * @brief Records loaded code object's host address in @p host_address given + * loaded code object's device address. Recorded host address points to host + * accessible memory, which is identical to memory pointed to by device address. + * If device address already points to host accessible memory, then device + * address is recorded in @p host_address. + * + * @param[in] device_address Device address. + * + * @param[out] host_address Pointer to application-allocated buffer, where to + * record host address. + * + * @retval HSA_STATUS_SUCCESS Function has been executed successfully. + * + * @retval HSA_STATUS_ERROR_NOT_INITIALIZED Runtime has not been initialized. + * + * @retval HSA_STATUS_ERROR_INVALID_ARGUMENT @p device address is invalid/null, + * or @p host address is null. + */ +hsa_status_t HSA_API hsa_ven_amd_loaded_code_object_query_host_address( + const void *device_address, + const void **host_address); + +/** + * @brief Extension's version. + */ +#define hsa_ven_amd_loaded_code_object 001000 + +/** + * @brief Extension's function table. + */ +typedef struct hsa_ven_amd_loaded_code_object_1_00_pfn_s { + hsa_status_t (*hsa_ven_amd_loaded_code_object_query_host_address)( + const void *device_address, + const void **host_address); +} hsa_ven_amd_loaded_code_object_1_00_pfn_t; + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif // HSA_VEN_AMD_LOADED_CODE_OBJECT_H