Program Listing for File DataType.hpp
↰ Return to documentation for file (nvcv_types/include/nvcv/DataType.hpp
)
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* 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 NVCV_DATA_TYPE_HPP
#define NVCV_DATA_TYPE_HPP
#include "DataLayout.hpp"
#include "DataType.h"
#include <iostream>
namespace nvcv {
enum class Byte : uint8_t
{
};
class DataType
{
public:
constexpr DataType();
explicit constexpr DataType(NVCVDataType type);
DataType(DataKind dataKind, Packing packing);
static constexpr DataType ConstCreate(DataKind dataKind, Packing packing);
constexpr operator NVCVDataType() const;
// Accessors for data type properties
Packing packing() const;
std::array<int32_t, 4> bitsPerChannel() const;
DataKind dataKind() const;
int32_t numChannels() const;
DataType channelType(int32_t channel) const;
int32_t strideBytes() const;
int32_t bitsPerPixel() const;
int32_t alignment() const;
private:
NVCVDataType m_type;
};
constexpr DataType::DataType()
: m_type(NVCV_DATA_TYPE_NONE)
{
}
constexpr DataType::DataType(NVCVDataType type)
: m_type(type)
{
}
#ifndef DOXYGEN_SHOULD_SKIP_THIS
constexpr DataType TYPE_U8{NVCV_DATA_TYPE_U8};
constexpr DataType TYPE_2U8{NVCV_DATA_TYPE_2U8};
constexpr DataType TYPE_3U8{NVCV_DATA_TYPE_3U8};
constexpr DataType TYPE_4U8{NVCV_DATA_TYPE_4U8};
constexpr DataType TYPE_S8{NVCV_DATA_TYPE_S8};
constexpr DataType TYPE_2S8{NVCV_DATA_TYPE_2S8};
constexpr DataType TYPE_3S8{NVCV_DATA_TYPE_3S8};
constexpr DataType TYPE_4S8{NVCV_DATA_TYPE_4S8};
constexpr DataType TYPE_U16{NVCV_DATA_TYPE_U16};
constexpr DataType TYPE_2U16{NVCV_DATA_TYPE_2U16};
constexpr DataType TYPE_3U16{NVCV_DATA_TYPE_3U16};
constexpr DataType TYPE_4U16{NVCV_DATA_TYPE_4U16};
constexpr DataType TYPE_S16{NVCV_DATA_TYPE_S16};
constexpr DataType TYPE_2S16{NVCV_DATA_TYPE_2S16};
constexpr DataType TYPE_3S16{NVCV_DATA_TYPE_3S16};
constexpr DataType TYPE_4S16{NVCV_DATA_TYPE_4S16};
constexpr DataType TYPE_U32{NVCV_DATA_TYPE_U32};
constexpr DataType TYPE_2U32{NVCV_DATA_TYPE_2U32};
constexpr DataType TYPE_3U32{NVCV_DATA_TYPE_3U32};
constexpr DataType TYPE_4U32{NVCV_DATA_TYPE_4U32};
constexpr DataType TYPE_S32{NVCV_DATA_TYPE_S32};
constexpr DataType TYPE_2S32{NVCV_DATA_TYPE_2S32};
constexpr DataType TYPE_3S32{NVCV_DATA_TYPE_3S32};
constexpr DataType TYPE_4S32{NVCV_DATA_TYPE_4S32};
constexpr DataType TYPE_F16{NVCV_DATA_TYPE_F16};
constexpr DataType TYPE_2F16{NVCV_DATA_TYPE_2F16};
constexpr DataType TYPE_3F16{NVCV_DATA_TYPE_3F16};
constexpr DataType TYPE_4F16{NVCV_DATA_TYPE_4F16};
constexpr DataType TYPE_F32{NVCV_DATA_TYPE_F32};
constexpr DataType TYPE_2F32{NVCV_DATA_TYPE_2F32};
constexpr DataType TYPE_3F32{NVCV_DATA_TYPE_3F32};
constexpr DataType TYPE_4F32{NVCV_DATA_TYPE_4F32};
constexpr DataType TYPE_U64{NVCV_DATA_TYPE_U64};
constexpr DataType TYPE_2U64{NVCV_DATA_TYPE_2U64};
constexpr DataType TYPE_3U64{NVCV_DATA_TYPE_3U64};
constexpr DataType TYPE_4U64{NVCV_DATA_TYPE_4U64};
constexpr DataType TYPE_S64{NVCV_DATA_TYPE_S64};
constexpr DataType TYPE_2S64{NVCV_DATA_TYPE_2S64};
constexpr DataType TYPE_3S64{NVCV_DATA_TYPE_3S64};
constexpr DataType TYPE_4S64{NVCV_DATA_TYPE_4S64};
constexpr DataType TYPE_F64{NVCV_DATA_TYPE_F64};
constexpr DataType TYPE_2F64{NVCV_DATA_TYPE_2F64};
constexpr DataType TYPE_3F64{NVCV_DATA_TYPE_3F64};
constexpr DataType TYPE_4F64{NVCV_DATA_TYPE_4F64};
constexpr DataType TYPE_C64{NVCV_DATA_TYPE_C64};
constexpr DataType TYPE_2C64{NVCV_DATA_TYPE_2C64};
constexpr DataType TYPE_3C64{NVCV_DATA_TYPE_3C64};
constexpr DataType TYPE_4C64{NVCV_DATA_TYPE_4C64};
constexpr DataType TYPE_C128{NVCV_DATA_TYPE_C128};
constexpr DataType TYPE_2C128{NVCV_DATA_TYPE_2C128};
#endif
inline DataType::DataType(DataKind dataKind, Packing packing)
{
detail::CheckThrow(
nvcvMakeDataType(&m_type, static_cast<NVCVDataKind>(dataKind), static_cast<NVCVPacking>(packing)));
}
constexpr DataType DataType::ConstCreate(DataKind dataKind, Packing packing)
{
return DataType{NVCV_MAKE_DATA_TYPE(static_cast<NVCVDataKind>(dataKind), static_cast<NVCVPacking>(packing))};
}
constexpr DataType::operator NVCVDataType() const
{
return m_type;
}
inline Packing DataType::packing() const
{
NVCVPacking out;
detail::CheckThrow(nvcvDataTypeGetPacking(m_type, &out));
return static_cast<Packing>(out);
}
inline int32_t DataType::bitsPerPixel() const
{
int32_t out;
detail::CheckThrow(nvcvDataTypeGetBitsPerPixel(m_type, &out));
return out;
}
inline std::array<int32_t, 4> DataType::bitsPerChannel() const
{
int32_t bits[4];
detail::CheckThrow(nvcvDataTypeGetBitsPerChannel(m_type, bits));
return {bits[0], bits[1], bits[2], bits[3]};
}
inline DataKind DataType::dataKind() const
{
NVCVDataKind out;
detail::CheckThrow(nvcvDataTypeGetDataKind(m_type, &out));
return static_cast<DataKind>(out);
}
inline int32_t DataType::numChannels() const
{
int32_t out;
detail::CheckThrow(nvcvDataTypeGetNumChannels(m_type, &out));
return out;
}
inline DataType DataType::channelType(int32_t channel) const
{
NVCVDataType out;
detail::CheckThrow(nvcvDataTypeGetChannelType(m_type, channel, &out));
return static_cast<DataType>(out);
}
inline int32_t DataType::strideBytes() const
{
int32_t out;
detail::CheckThrow(nvcvDataTypeGetStrideBytes(m_type, &out));
return out;
}
inline int32_t DataType::alignment() const
{
int32_t out;
detail::CheckThrow(nvcvDataTypeGetAlignment(m_type, &out));
return out;
}
inline std::ostream &operator<<(std::ostream &out, DataType type)
{
return out << nvcvDataTypeGetName(type);
}
} // namespace nvcv
#endif // NVCV_DATA_TYPE_HPP