/*========================== begin_copyright_notice ============================
Copyright (C) 2021-2025 Intel Corporation

SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/

/*!
 * @file Utility for filtering profiled kernel dispatches per enqueue, draw, device, commandlist, PSO
 */

#ifndef KERNEL_EXEC_CONFIG_H_
#define KERNEL_EXEC_CONFIG_H_

#include <tuple>
#include <vector>
#include "api/gt_gpu_defs.h"

/*!
* Tuple that holds kernel enqueue data { kernel name , enqueue range min , enqueue range max }
*/
using kernelEnqueueInfo = std::tuple<std::string, uint32_t, uint32_t>;

namespace gtpin
{
/*!
 * Singleton that holds common configuration options for filtering profiled kernel dispatches:
 *  --enqueue           enqueues to profile
 *  --draw              draws to profile
 *  --device            devices to profile
 *  --cl                command lists to profile
 *  --pso               PSO IDs to profile
 *  --frame             frame IDs to profile
 *
 *  --skip_enqueue     enqueues to skip (don't profile)
 *  --skip_draw        draws to skip (don't profile)
 *  --skip_device      devices to skip (don't profile)
 *  --skip_cl          command lists to skip (don't profile)
 *  --skip_pso         PSO IDs to skip (don't profile)
 *  --skip_frame       frame IDs to skip (don't profile)
 */
class KernelExecConfig
{
public:
    /// Get single instance of this class
    static KernelExecConfig& Instance();

    /// @return true if kernel dispatch with the specified descriptor should be profiled
    bool IsProfileEnabled(const GtKernelExecDesc& execDesc, GPU_PLATFORM platform,const char* kernelName = nullptr) const;

public:
    std::vector<kernelEnqueueInfo>  enqueues;
    std::vector<uint32_t>           draw;
    std::vector<uint32_t>           device;
    std::vector<uint32_t>           cl;
    std::vector<uint32_t>           pso;
    std::vector<uint32_t>           frame;

    std::vector<kernelEnqueueInfo>  skipEnqueue;
    std::vector<uint32_t>           skipDraw;
    std::vector<uint32_t>           skipDevice;
    std::vector<uint32_t>           skipCl;
    std::vector<uint32_t>           skipPso;
    std::vector<uint32_t>           skipFrame;

    bool isEmptyFilter;

private:
    /// Construct this singleton with the profile filtering options as specified in the command line
    KernelExecConfig();

    KernelExecConfig(const KernelExecConfig&) = delete;
    KernelExecConfig& operator = (const KernelExecConfig&) = delete;
    ~KernelExecConfig() = default;
};

/// @return true if kernel dispatch with the specified descriptor should be profiled
inline bool IsKernelExecProfileEnabled(const GtKernelExecDesc& execDesc, GPU_PLATFORM platform ,const char* kernelName = nullptr)
{
    return KernelExecConfig::Instance().IsProfileEnabled(execDesc, platform, kernelName);
}

}
#endif