#include <unordered_map>
#include "gpu/intel/engine.hpp"
#include "common/rw_mutex.hpp"
#include "common/utils.hpp"
namespace dnnl {
namespace impl {
namespace gpu {
namespace intel {
using device_info_cache_t = std::unordered_map<gpu_utils::device_id_t,
std::shared_ptr<compute::device_info_t>, gpu_utils::device_id_hash_t>;
utils::rw_mutex_t &device_info_cache_mutex() {
static utils::rw_mutex_t m;
return m;
}
device_info_cache_t &device_info_cache() {
static device_info_cache_t cache;
return cache;
}
bool device_info_cache_get(std::shared_ptr<compute::device_info_t> *result,
impl::engine_t *engine) {
utils::lock_read_t lock(device_info_cache_mutex());
auto *intel_engine = utils::downcast<engine_t *>(engine);
auto it = device_info_cache().find(intel_engine->device_id());
if (it == device_info_cache().end()) return false;
if (result) *result = it->second;
return true;
}
void device_info_cache_set(impl::engine_t *engine,
const std::shared_ptr<compute::device_info_t> &device_info) {
utils::lock_write_t lock(device_info_cache_mutex());
auto *intel_engine = utils::downcast<engine_t *>(engine);
const int cache_size_threshold = 1024;
if (device_info_cache().size() > cache_size_threshold)
device_info_cache().clear();
device_info_cache().insert({intel_engine->device_id(), device_info});
}
status_t engine_t::init() {
return init({});
}
status_t engine_t::init(const std::vector<uint8_t> &cache_blob) {
if (device_info_cache_get(&device_info_, this)) return status::success;
if (cache_blob.empty())
CHECK(init_device_info());
else
CHECK(init_device_info(cache_blob));
device_info_cache_set(this, device_info_);
return status::success;
}
} } } }
bool dnnl_impl_gpu_intel_mayiuse_ngen_kernels(dnnl::impl::engine_t *engine) {
using namespace dnnl::impl;
using namespace dnnl::impl::gpu;
auto *intel_engine = utils::downcast<intel::engine_t *>(engine);
return intel_engine->mayiuse_ngen_kernels();
}
const char *dnnl_impl_gpu_intel_get_isa_name(dnnl::impl::engine_t *engine) {
using namespace dnnl::impl;
using namespace dnnl::impl::gpu;
auto *intel_engine = utils::downcast<intel::engine_t *>(engine);
auto *device_info = intel_engine->device_info();
return intel::compute::to_string(device_info->gpu_arch());
}