#include "gpu/intel/ze/stream.hpp"
#include "gpu/intel/ze/engine.hpp"
#include "xpu/ze/stream_profiler.hpp"
namespace dnnl {
namespace impl {
namespace gpu {
namespace intel {
namespace ze {
status_t stream_t::create_stream(impl::stream_t **stream,
impl::engine_t *engine, impl::stream_impl_t *stream_impl) {
std::unique_ptr<intel::ze::stream_t> s(new stream_t(engine, stream_impl));
if (!s) return status::out_of_memory;
status_t status = s->init();
if (status != status::success) {
s->impl_.release();
return status;
}
*stream = s.release();
return status::success;
}
status_t stream_t::init() {
if (is_profiling_enabled()) {
ze_device_properties_t device_properties {};
device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES_1_2;
CHECK(xpu::ze::zeDeviceGetProperties(
utils::downcast<engine_t *>(engine())->device(),
&device_properties));
uint64_t max_timestamp_value
= (1ULL << device_properties.kernelTimestampValidBits) - 1;
profiler_ = utils::make_unique<xpu::ze::stream_profiler_t>(this,
1e9 / device_properties.timerResolution, max_timestamp_value);
}
return status::success;
}
void stream_t::before_exec_hook() {
if (is_profiling_enabled()) profiler_->start_profiling();
}
void stream_t::after_exec_hook() {
ze_ctx().set_deps(xpu::ze::event_t());
if (is_profiling_enabled()) profiler_->stop_profiling();
}
status_t stream_t::reset_profiling() {
if (!is_profiling_enabled()) return status::invalid_arguments;
profiler_->reset();
return status::success;
}
status_t stream_t::get_profiling_data(profiling_data_kind_t data_kind,
int *num_entries, uint64_t *data) const {
if (!is_profiling_enabled()) return status::invalid_arguments;
return profiler_->get_info(data_kind, num_entries, data);
}
} } } } }