move executable_cache into program_state.cpp
[ROCm/clr commit: 1a2d332e76]
This commit is contained in:
@@ -30,39 +30,12 @@ THE SOFTWARE.
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
struct ihipModuleSymbol_t;
|
struct ihipModuleSymbol_t;
|
||||||
using hipFunction_t = 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 {
|
namespace hip_impl {
|
||||||
|
|
||||||
[[noreturn]]
|
|
||||||
void hip_throw(const std::exception&);
|
|
||||||
|
|
||||||
class kernargs_size_align;
|
class kernargs_size_align;
|
||||||
class program_state_impl;
|
class program_state_impl;
|
||||||
class program_state {
|
class program_state {
|
||||||
|
|||||||
@@ -2492,13 +2492,4 @@ namespace hip_impl {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex executables_cache_mutex;
|
|
||||||
|
|
||||||
std::vector<hsa_executable_t>& executables_cache(
|
|
||||||
std::string elf, hsa_isa_t isa, hsa_agent_t agent) {
|
|
||||||
static std::unordered_map<std::string,
|
|
||||||
std::unordered_map<hsa_isa_t,
|
|
||||||
std::unordered_map<hsa_agent_t, std::vector<hsa_executable_t>>>> cache;
|
|
||||||
return cache[elf][isa][agent];
|
|
||||||
}
|
|
||||||
} // Namespace hip_impl.
|
} // Namespace hip_impl.
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "../include/hip/hcc_detail/program_state.hpp"
|
#include "../include/hip/hcc_detail/program_state.hpp"
|
||||||
|
// contains implementation of program_state_impl
|
||||||
|
#include "program_state.inl"
|
||||||
|
|
||||||
#include <hsa/hsa.h>
|
#include <hsa/hsa.h>
|
||||||
|
|
||||||
@@ -7,53 +9,58 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// contains implementation of program_state_impl
|
|
||||||
#include "program_state.inl"
|
|
||||||
|
|
||||||
namespace hip_impl {
|
namespace hip_impl {
|
||||||
|
|
||||||
std::size_t kernargs_size_align::kernargs_size_align::size(std::size_t n) const{
|
std::size_t kernargs_size_align::kernargs_size_align::size(std::size_t n) const{
|
||||||
return (*reinterpret_cast<const std::vector<std::pair<std::size_t, std::size_t>>*>(handle))[n].first;
|
return (*reinterpret_cast<const std::vector<std::pair<std::size_t, std::size_t>>*>(handle))[n].first;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t kernargs_size_align::alignment(std::size_t n) const{
|
std::size_t kernargs_size_align::alignment(std::size_t n) const{
|
||||||
return (*reinterpret_cast<const std::vector<std::pair<std::size_t, std::size_t>>*>(handle))[n].second;
|
return (*reinterpret_cast<const std::vector<std::pair<std::size_t, std::size_t>>*>(handle))[n].second;
|
||||||
}
|
}
|
||||||
|
|
||||||
program_state::program_state() :
|
program_state::program_state() : impl(new program_state_impl) {
|
||||||
impl(new program_state_impl) {
|
if (!impl) hip_throw(std::runtime_error {
|
||||||
if (!impl) hip_throw(std::runtime_error {
|
"Unknown error when constructing program state."});
|
||||||
"Unknown error when constructing program state."});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
program_state::~program_state() {
|
program_state::~program_state() {
|
||||||
delete(impl);
|
delete(impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* program_state::global_addr_by_name(const char* name) {
|
void* program_state::global_addr_by_name(const char* name) {
|
||||||
const auto it = impl->get_globals().find(name);
|
const auto it = impl->get_globals().find(name);
|
||||||
if (it == impl->get_globals().end())
|
if (it == impl->get_globals().end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
else
|
else
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
hsa_executable_t program_state::load_executable(const char* data,
|
hsa_executable_t program_state::load_executable(const char* data,
|
||||||
const size_t data_size,
|
const size_t data_size,
|
||||||
hsa_executable_t executable,
|
hsa_executable_t executable,
|
||||||
hsa_agent_t agent) {
|
hsa_agent_t agent) {
|
||||||
return impl->load_executable(data, data_size, executable, agent);
|
return impl->load_executable(data, data_size, executable, agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
hipFunction_t program_state::kernel_descriptor(std::uintptr_t function_address,
|
hipFunction_t program_state::kernel_descriptor(std::uintptr_t function_address,
|
||||||
hsa_agent_t agent) {
|
hsa_agent_t agent) {
|
||||||
auto& kd = impl->kernel_descriptor(function_address, agent);
|
auto& kd = impl->kernel_descriptor(function_address, agent);
|
||||||
return kd;
|
return kd;
|
||||||
}
|
}
|
||||||
|
|
||||||
kernargs_size_align program_state::get_kernargs_size_align(std::uintptr_t kernel) {
|
kernargs_size_align program_state::get_kernargs_size_align(std::uintptr_t kernel) {
|
||||||
kernargs_size_align t;
|
kernargs_size_align t;
|
||||||
t.handle = reinterpret_cast<const void*>(&impl->kernargs_size_align(kernel));
|
t.handle = reinterpret_cast<const void*>(&impl->kernargs_size_align(kernel));
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::mutex executables_cache_mutex;
|
||||||
|
std::vector<hsa_executable_t>& executables_cache(
|
||||||
|
std::string elf, hsa_isa_t isa, hsa_agent_t agent) {
|
||||||
|
static std::unordered_map<std::string,
|
||||||
|
std::unordered_map<hsa_isa_t,
|
||||||
|
std::unordered_map<hsa_agent_t, std::vector<hsa_executable_t>>>> cache;
|
||||||
|
return cache[elf][isa][agent];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,12 +26,36 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
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 {
|
namespace hip_impl {
|
||||||
|
|
||||||
[[noreturn]]
|
[[noreturn]]
|
||||||
|
|||||||
Reference in New Issue
Block a user