//===----------------------------------------------------------------------===// // // Part of the libcu++ Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. // //===----------------------------------------------------------------------===// #ifndef SUPPORT_HIERARCHY_QUERIES_H #define SUPPORT_HIERARCHY_QUERIES_H #include #include #include #include #include "test_macros.h" template TEST_DEVICE_FUNC void test_result(cuda::hierarchy_query_result res, Vec exp) { assert(res.x == static_cast(exp.x)); assert(res.y == static_cast(exp.y)); assert(res.z == static_cast(exp.z)); } template TEST_DEVICE_FUNC void test_result(cuda::std::extents res, cuda::std::extents exp) { for (cuda::std::size_t i = 0; i < sizeof...(Exts); ++i) { assert(res.extent(i) == static_cast(exp.extent(i))); } } template TEST_DEVICE_FUNC void test_dims(const uint3 exp, const Level& level, Args... args) { test_result(level.dims(args...), exp); test_result(level.template dims_as(args...), exp); test_result(level.template dims_as(args...), exp); test_result(level.template dims_as(args...), exp); test_result(level.template dims_as(args...), exp); test_result(level.template dims_as(args...), exp); test_result(level.template dims_as(args...), exp); } template TEST_DEVICE_FUNC void test_static_dims(const ulonglong3 exp, Level level, Args... args) { static_assert(level.static_dims(args...).x != 0); test_result(level.static_dims(args...), exp); } template TEST_DEVICE_FUNC void test_extents(const Exp exp, const Level& level, Args... args) { test_result(level.extents(args...), exp); test_result(level.template extents_as(args...), exp); test_result(level.template extents_as(args...), exp); test_result(level.template extents_as(args...), exp); test_result(level.template extents_as(args...), exp); test_result(level.template extents_as(args...), exp); test_result(level.template extents_as(args...), exp); } template TEST_DEVICE_FUNC void test_static_count(Level level, Args... args) { constexpr auto static_dims = level.static_dims(args...); if constexpr (static_dims.x != cuda::std::dynamic_extent && static_dims.y != cuda::std::dynamic_extent && static_dims.z != cuda::std::dynamic_extent) { static_assert(level.static_count(args...) == static_dims.x * static_dims.y * static_dims.z); } else { static_assert(level.static_count(args...) == cuda::std::dynamic_extent); } } template TEST_DEVICE_FUNC void test_count(const cuda::std::size_t exp, const Level& level, Args... args) { assert(level.count(args...) == exp); assert(level.template count_as(args...) == static_cast(exp)); assert(level.template count_as(args...) == static_cast(exp)); assert(level.template count_as(args...) == static_cast(exp)); assert(level.template count_as(args...) == static_cast(exp)); assert(level.template count_as(args...) == static_cast(exp)); assert(level.template count_as(args...) == static_cast(exp)); } template TEST_DEVICE_FUNC void test_index(const uint3 exp, const Level& level, Args... args) { test_result(level.index(args...), exp); test_result(level.template index_as(args...), exp); test_result(level.template index_as(args...), exp); test_result(level.template index_as(args...), exp); test_result(level.template index_as(args...), exp); test_result(level.template index_as(args...), exp); test_result(level.template index_as(args...), exp); } template TEST_DEVICE_FUNC void test_rank(const cuda::std::size_t exp, const Level& level, Args... args) { assert(level.rank(args...) == exp); assert(level.template rank_as(args...) == static_cast(exp)); assert(level.template rank_as(args...) == static_cast(exp)); assert(level.template rank_as(args...) == static_cast(exp)); assert(level.template rank_as(args...) == static_cast(exp)); assert(level.template rank_as(args...) == static_cast(exp)); assert(level.template rank_as(args...) == static_cast(exp)); } template TEST_DEVICE_FUNC constexpr cuda::std::size_t mul_static_extents(Args... args) { if (((args == cuda::std::dynamic_extent) || ...)) { return cuda::std::dynamic_extent; } else { return (cuda::std::size_t{1} * ... * args); } } #endif // SUPPORT_HIERARCHY_QUERIES_H