/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/

#ifndef GPU_INTEL_OCL_VERBOSE_HPP
#define GPU_INTEL_OCL_VERBOSE_HPP

#include <cstdio>

#include "xpu/ocl/engine_impl.hpp"

#if DNNL_GPU_VENDOR == DNNL_VENDOR_INTEL
#include "gpu/intel/compute/device_info.hpp"
#include "gpu/intel/ocl/ocl_engine.hpp"
#endif

namespace dnnl {
namespace impl {
namespace gpu {
namespace intel {
namespace ocl {

void print_verbose_header() {
    ocl_engine_factory_t factory(engine_kind::gpu);
    for (size_t i = 0; i < factory.count(); ++i) {
        impl::engine_t *eng_ptr = nullptr;
        status_t status = factory.engine_create(&eng_ptr, i);
        if (status != status::success) {
            VERROR(common, ocl, VERBOSE_INVALID_DEVICE_ENV,
                    dnnl_engine_kind2str(engine_kind::gpu), i);
            continue;
        }

        const auto *engine_impl
                = utils::downcast<const xpu::ocl::engine_impl_t *>(
                        eng_ptr->impl());
        auto s_name = engine_impl->name();
        auto s_ver = engine_impl->runtime_version().str();

#if DNNL_GPU_VENDOR == DNNL_VENDOR_INTEL
        auto *compute_engine
                = utils::downcast<compute::compute_engine_t *>(eng_ptr);
        auto *dev_info = compute_engine->device_info();
        printf("onednn_verbose,info,gpu,engine,%d,name:%s,"
               "driver_version:%s,binary_kernels:%s\n",
                (int)i, s_name.c_str(), s_ver.c_str(),
                dev_info->mayiuse_ngen_kernels() ? "enabled" : "disabled");
        return;
#endif
        printf("onednn_verbose,info,gpu,engine,%d,name:%s,"
               "driver_version:%s\n",
                (int)i, s_name.c_str(), s_ver.c_str());
        eng_ptr->release();
    }
}

} // namespace ocl
} // namespace intel
} // namespace gpu
} // namespace impl
} // namespace dnnl

#endif
