cupva_host_utils.hpp#

Fully qualified name: src/host_utils/core/include/cupva_host_utils.hpp

File members: src/host_utils/core/include/cupva_host_utils.hpp

/*
 * Copyright (c) 2021, NVIDIA CORPORATION.  All rights reserved.
 *
 * NVIDIA CORPORATION and its licensors retain all intellectual property
 * and proprietary rights in and to this software, related documentation
 * and any modifications thereto.  Any use, reproduction, disclosure or
 * distribution of this software and related documentation without an express
 * license agreement from NVIDIA CORPORATION is strictly prohibited.
 */

#ifndef CUPVA_HOST_UTILS_HPP
#define CUPVA_HOST_UTILS_HPP

#include <cupva_host.hpp>

#include <string>

namespace cupva_utils {

struct PlaneSize
{
    int32_t width;
    int32_t height;
};

enum class ProfilingBatchStatType : uint32_t
{
    EXECUTION_TIME = 0,
    TASK_OVERHEAD,
    TOTAL_TIME,
    MAX_TYPE
};

enum class ProfilingProgramStatType : uint32_t
{
    EXECUTION_TIME = 0,
    SETUP_TIME,
    TEARDOWN_TIME,
    MAX_TYPE
};

struct ProfilingStatisticsData
{
    uint64_t minTime;
    uint64_t maxTime;
    uint64_t totalTime;
    uint64_t avgTime;
    uint64_t *data;
    int32_t count;
};

class DLL_EXPORT ProfilingStatistics
{
public:
    ProfilingStatistics() noexcept
        : m_stats{}
        , m_dataPtr{nullptr}
    {
    }
    ProfilingStatistics(ProfilingStatisticsData const &stats);

    ~ProfilingStatistics() noexcept = default;
    ProfilingStatistics(ProfilingStatistics &&obj) noexcept;
    ProfilingStatistics &operator=(ProfilingStatistics &&obj) & noexcept;
    ProfilingStatistics(ProfilingStatistics const &) = delete;
    ProfilingStatistics &operator=(ProfilingStatistics const &) = delete;

    ProfilingStatisticsData const &getStatsData() const;

private:
    // variable for storing profiling statistics.
    ProfilingStatisticsData m_stats;
    // buffer for storing profiling fine-grained data.
    std::unique_ptr<uint64_t[]> m_dataPtr;
};

DLL_EXPORT std::ostream &operator<<(std::ostream &os, ProfilingStatistics const &stats);

namespace impl {

// forward declaration of class ProfilingContext
class ProfilingContext;
} // namespace impl

class DLL_EXPORT ProfilingContext : public cupva::DynamicStorage<impl::ProfilingContext>
{
public:
    ProfilingContext();

    ProfilingContext(ProfilingContext &&obj);

    ProfilingContext &operator=(ProfilingContext &&obj) &;

    ~ProfilingContext() noexcept;

    static ProfilingContext Create();

    ProfilingStatistics getStatistics(ProfilingBatchStatType const type);

    ProfilingStatistics getStatistics(cupva::CmdProgram const &prog, ProfilingProgramStatType const type);

    ProfilingStatistics getStatistics(cupva::Executable const &exec, ProfilingProgramStatType const type);

    void reset();
};

DLL_EXPORT void *AllocSurface(const PlaneSize *ps, const int32_t planeCount,
                              const cupva::SurfaceFormatType format = cupva::SurfaceFormatType::BLOCK_LINEAR);

DLL_EXPORT void CopyToPlane(void *dstPlaneBase, const void *src, const int32_t imageWidth, const int32_t imageHeight);

DLL_EXPORT void CopyFromPlane(void *dst, const void *srcPlaneBase, const int32_t imageWidth, const int32_t imageHeight);

DLL_EXPORT cupva::Stream CreateSyncStream(cupva::EngineType absEngine     = cupva::EngineType::PVA0,
                                          cupva::AffinityType vpuAffinity = cupva::AffinityType::VPU_ANY);

DLL_EXPORT cupva::Stream CreateSyncStream(cupva::Stream stream);

DLL_EXPORT cupva::Stream CreateProfilingStream(ProfilingContext &ctx,
                                               cupva::EngineType absEngine     = cupva::EngineType::PVA0,
                                               cupva::AffinityType vpuAffinity = cupva::AffinityType::VPU_ANY);

DLL_EXPORT std::string DMAPerfWarnings(cupva::CmdProgram &program);

DLL_EXPORT std::string PrintDMAGraph(cupva::CmdProgram &program);

DLL_EXPORT std::string LogDescriptors(cupva::CmdProgram &program);

DLL_EXPORT std::string LogChannels(cupva::CmdProgram &program);

} // namespace cupva_utils

#endif