tensor_dataflow.h#

Fully qualified name: src/device/vpu_runtime/include/cupva_device/tensor_dataflow.h

File members: src/device/vpu_runtime/include/cupva_device/tensor_dataflow.h

/*
 * SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
 *
 * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
 * property and proprietary rights in and to this material, related
 * documentation and any modifications thereto. Any use, reproduction,
 * disclosure or distribution of this material and related documentation
 * without an express license agreement from NVIDIA CORPORATION or
 * its affiliates is strictly prohibited.
 */

#ifndef CUPVA_DEVICE_TENSOR_DATAFLOW_H
#define CUPVA_DEVICE_TENSOR_DATAFLOW_H

#include "impl/dma_common.h"

#include <cupva_types.h>
#include <stdint.h>

struct TDFHandler
{
    UnifiedRDFHandler ctx;
    TensorDataFlowParams params;
};

#define VMEM_TDF_HANDLER(bank, name)  \
    VMEM_VAR(bank, TDFHandler, name); \
    CUPVA_EXPORT(name.ctx.hdl, name); \
    CUPVA_EXPORT(name.params, _M##name);

#define TDF_SINGLE(type, tw, th, tz, ...) RDF_SINGLE(type, tw, th, ##__VA_ARGS__) * tz

#define TDF_DOUBLE(type, tw, th, tz, ...) \
    (CIRCULAR_BUFFER_ALIGNED_SIZE((RDF_SINGLE(type, tw, th, ##__VA_ARGS__)) * 2 * sizeof(type)) / sizeof(type)) * tz

inline uint32_t cupvaTensorDataFlowGetBppLog2(TDFHandler const &handler)
{
    return CUPVA_EXTRACT_FIELD(RDF_TRANSFER_PROPERTIES_BPPLOG2, (uint32_t)handler.ctx.hdl.transferProperties);
}

inline uint32_t cupvaTensorDataFlowGetTileLinePitch(TDFHandler const &handler)
{
    return handler.ctx.hdl.linePitch;
}

inline uint32_t cupvaTensorDataFlowGetTilePlaneSize(TDFHandler const &handler)
{
    return handler.params.tilePlaneSize;
}

inline uint32_t cupvaTensorDataFlowGetNumTiles(TDFHandler const &handler)
{
    int32_t idx = (handler.ctx.hdl.ixAdv == 0U) ? 1 : 0;
    return handler.params.tileDepth[idx];
}

inline uint32_t cupvaTensorDataFlowGetNiterC(TDFHandler const &handler)
{
    int32_t nxm1 = handler.ctx.hdl.nxm1;
    return (nxm1 + 1U);
}

inline uint32_t cupvaTensorDataFlowGetNiterHW(TDFHandler const &handler)
{
    return handler.params.niterHW;
}

inline bool cupvaTensorDataFlowZHasRemainder(TDFHandler const &handler)
{
    return (handler.params.numSlices > 1U);
}

inline void cupvaTensorDataFlowOpen(TDFHandler &handler, void *vmemBuffer)
{
    cupvaRasterDataFlowOpen(handler.ctx, vmemBuffer);
}

inline void *cupvaTensorDataFlowAcquire(TDFHandler &handler)
{
    return cupvaRasterDataFlowAcquire(handler.ctx);
}

inline void cupvaTensorDataFlowRelease(TDFHandler &handler)
{
    cupvaRasterDataFlowRelease(handler.ctx);
}

inline void cupvaTensorDataFlowClose(TDFHandler &handler)
{
    cupvaDataFlowSync(handler.ctx.nextSync);
}

#endif