f5eb91d53d
* Revert "Revert "Use COMgr to read Kernel Args Metadata (#1006)"" This reverts commita3d118eaa8. * Revert "Use COMgr to read Kernel Args Metadata (#1006)" This reverts commit8a548bf40b. * Revert "improve program state commentary" This reverts commit7aada87cbd. * Revert "load program state once per agent" This reverts commitc9117de8eb. * start moving function_names() into the hip shared lib * start moving code_object_blobs to a new "state" object * Consolidate various program state related static objects into a single program_state object * minor clean up * move more stuffs from functional_grid_launch into program_state * debug make_kernarg * moving lookup for kernargs size_align into program_state * clean up old code for kernarg size and alignment * update hip_module to use newer api in program_state * Create public member functions for program_state * move most program state functions into shared library * Pass the data buffer size to load_executable Otherwise, it can't figure what the data size is just from the char* (since the data is not really a string) * turning free functions in program state into members of program_state_impl * change the free function globals() into a member of program_state_impl * replace the static mutex used for populating globals * moving associate_code_object_symbols_with_host_allocation into program_state_impl * move load_code_object_and_freeze_executable into program_state_impl * moving executables and functions_names into program_state_impl * moving kernels() into program_state_impl * moving functions() into program_state_impl * move get_kernargs into program_state_impl * moving kernel_descriptor into program_state_impl * moving kernargs_size_align calculation into program_state_impl * Changing the handle to program_state_impl to a pointer * moving program_state_impl into a separate inline source file * fixing/cleaning up some header file includes * moving member function for kernargs_size_align into program_state.cpp * moving Kernel_descriptor into program_state.inl * add a new class to manage agent globals * moving all agent globals processing functions into agent_globals_impl * load program state once per agent re-merging PR991 against other program state changes * fix per-agent program state member initialization * cache executables based on elf name, isa, and agent. This avoids program state reloading executables after a shared library is dlopened. re-merging PR1057 against other program state changes * protect executables cache by a global mutex * return ref to executables cache * adapt PR#981 Make hipModuleGetGlobal be in HIP runtime
111 lines
3.1 KiB
C++
111 lines
3.1 KiB
C++
/*
|
|
Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in 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:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
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
|
|
AUTHORS 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 IN
|
|
THE SOFTWARE.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <hsa/amd_hsa_kernel_code.h>
|
|
#include <hsa/hsa.h>
|
|
#include <hsa/hsa_ext_amd.h>
|
|
#include <hsa/hsa_ven_amd_loader.h>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
struct ihipModuleSymbol_t;
|
|
using hipFunction_t = ihipModuleSymbol_t*;
|
|
|
|
namespace std {
|
|
template<>
|
|
struct hash<hsa_agent_t> {
|
|
size_t operator()(hsa_agent_t x) const {
|
|
return hash<decltype(x.handle)>{}(x.handle);
|
|
}
|
|
};
|
|
|
|
template<>
|
|
struct hash<hsa_isa_t> {
|
|
size_t operator()(hsa_isa_t x) const {
|
|
return hash<decltype(x.handle)>{}(x.handle);
|
|
}
|
|
};
|
|
} // namespace std
|
|
|
|
inline constexpr bool operator==(hsa_agent_t x, hsa_agent_t y) {
|
|
return x.handle == y.handle;
|
|
}
|
|
inline constexpr bool operator==(hsa_isa_t x, hsa_isa_t y) {
|
|
return x.handle == y.handle;
|
|
}
|
|
|
|
namespace hip_impl {
|
|
|
|
[[noreturn]]
|
|
void hip_throw(const std::exception&);
|
|
|
|
class kernargs_size_align;
|
|
class program_state_impl;
|
|
class program_state {
|
|
public:
|
|
program_state();
|
|
~program_state();
|
|
|
|
hipFunction_t kernel_descriptor(std::uintptr_t,
|
|
hsa_agent_t);
|
|
|
|
kernargs_size_align get_kernargs_size_align(std::uintptr_t);
|
|
hsa_executable_t load_executable(const char*, const size_t,
|
|
hsa_executable_t,
|
|
hsa_agent_t);
|
|
|
|
void* global_addr_by_name(const char* name);
|
|
|
|
// to fix later
|
|
const std::vector<hsa_executable_t>& executables(hsa_agent_t agent);
|
|
|
|
program_state(const program_state&) = delete;
|
|
|
|
private:
|
|
program_state_impl* impl;
|
|
};
|
|
|
|
class kernargs_size_align {
|
|
public:
|
|
std::size_t size(std::size_t n) const;
|
|
std::size_t alignment(std::size_t n) const;
|
|
private:
|
|
const void* handle;
|
|
friend kernargs_size_align program_state::get_kernargs_size_align(std::uintptr_t);
|
|
};
|
|
|
|
inline
|
|
__attribute__((visibility("hidden")))
|
|
program_state& get_program_state() {
|
|
static program_state ps;
|
|
return ps;
|
|
}
|
|
} // Namespace hip_impl.
|