/* Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include enum class ChannelDimension { OneDim, TwoDim, ThreeDim, FourDim }; template class ChannelDescriptorTestShell { protected: int size; hipChannelFormatKind kind; ChannelDimension dimension; virtual void SetSizeAndKind() = 0; public: void Run() { hipChannelFormatDesc channel_desc{}; SetSizeAndKind(); hipChannelFormatDesc referent_channel_desc{0, 0, 0, 0, kind}; switch (dimension) { case ChannelDimension::FourDim: referent_channel_desc.w = size; case ChannelDimension::ThreeDim: referent_channel_desc.z = size; case ChannelDimension::TwoDim: referent_channel_desc.y = size; default: referent_channel_desc.x = size; } channel_desc = hipCreateChannelDesc(); REQUIRE(channel_desc.x == referent_channel_desc.x); REQUIRE(channel_desc.y == referent_channel_desc.y); REQUIRE(channel_desc.z == referent_channel_desc.z); REQUIRE(channel_desc.w == referent_channel_desc.w); REQUIRE(channel_desc.f == referent_channel_desc.f); } ChannelDescriptorTestShell(const ChannelDimension dimension) : size(0), kind(hipChannelFormatKindNone), dimension(dimension) {} ChannelDescriptorTestShell(const ChannelDescriptorTestShell&) = delete; ChannelDescriptorTestShell(ChannelDescriptorTestShell&&) = delete; }; template class ChannelDescriptorTest1D : public ChannelDescriptorTestShell { public: ChannelDescriptorTest1D() : ChannelDescriptorTestShell(ChannelDimension::OneDim) {} protected: void SetSizeAndKind() { if (std::is_same_v) { this->size = static_cast(sizeof(char) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v || std::is_same_v) { this->size = static_cast(sizeof(unsigned char) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v || std::is_same_v) { this->size = static_cast(sizeof(signed char) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v || std::is_same_v) { this->size = static_cast(sizeof(unsigned short) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v || std::is_same_v || std::is_same_v) { this->size = static_cast(sizeof(signed short) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v || std::is_same_v) { this->size = static_cast(sizeof(unsigned int) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v || std::is_same_v || std::is_same_v) { this->size = static_cast(sizeof(signed int) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v || std::is_same_v) { this->size = static_cast(sizeof(float) * 8); this->kind = hipChannelFormatKindFloat; } #if !defined(__LP64__) else if (std::is_same_v || std::is_same_v) { this->size = static_cast(sizeof(unsigned long) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v || std::is_same_v || std::is_same_v) { this->size = static_cast(sizeof(signed long) * 8); this->kind = hipChannelFormatKindSigned; } #endif } }; template class ChannelDescriptorTest2D : public ChannelDescriptorTestShell { public: ChannelDescriptorTest2D() : ChannelDescriptorTestShell(ChannelDimension::TwoDim) {} protected: void SetSizeAndKind() { if (std::is_same_v) { this->size = static_cast(sizeof(unsigned char) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed char) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(unsigned short) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed short) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(unsigned int) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed int) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(float) * 8); this->kind = hipChannelFormatKindFloat; } #if !defined(__LP64__) else if (std::is_same_v) { this->size = static_cast(sizeof(unsigned long) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed long) * 8); this->kind = hipChannelFormatKindSigned; } #endif } }; #ifndef __GNUC__ template class ChannelDescriptorTest3D : public ChannelDescriptorTestShell { public: ChannelDescriptorTest3D() : ChannelDescriptorTestShell(ChannelDimension::ThreeDim) {} protected: void SetSizeAndKind() { if (std::is_same_v) { this->size = static_cast(sizeof(unsigned char) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed char) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(unsigned short) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed short) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(unsigned int) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed int) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(float) * 8); this->kind = hipChannelFormatKindFloat; } #if !defined(__LP64__) else if (std::is_same_v) { this->size = static_cast(sizeof(unsigned long) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed long) * 8); this->kind = hipChannelFormatKindSigned; } #endif } }; #endif template class ChannelDescriptorTest4D : public ChannelDescriptorTestShell { public: ChannelDescriptorTest4D() : ChannelDescriptorTestShell(ChannelDimension::FourDim) {} protected: void SetSizeAndKind() { if (std::is_same_v) { this->size = static_cast(sizeof(unsigned char) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed char) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(unsigned short) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed short) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(unsigned int) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed int) * 8); this->kind = hipChannelFormatKindSigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(float) * 8); this->kind = hipChannelFormatKindFloat; } #if !defined(__LP64__) else if (std::is_same_v) { this->size = static_cast(sizeof(unsigned long) * 8); this->kind = hipChannelFormatKindUnsigned; } else if (std::is_same_v) { this->size = static_cast(sizeof(signed long) * 8); this->kind = hipChannelFormatKindSigned; } #endif } }; template class ChannelDescriptorTestNone : public ChannelDescriptorTestShell { public: ChannelDescriptorTestNone() : ChannelDescriptorTestShell(ChannelDimension::OneDim) {} protected: void SetSizeAndKind() {} };