|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of CUDASTF in CUDA C++ Core Libraries, |
| 4 | +// under the Apache License v2.0 with LLVM Exceptions. |
| 5 | +// See https://llvm.org/LICENSE.txt for license information. |
| 6 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | +// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. |
| 8 | +// |
| 9 | +//===----------------------------------------------------------------------===// |
| 10 | + |
| 11 | +//! file |
| 12 | +//! !brief Check that multi-level launch specification are fulfilled |
| 13 | + |
| 14 | +#include <cuda/experimental/stf.cuh> |
| 15 | + |
| 16 | +#include <cassert> |
| 17 | +#include <iostream> |
| 18 | + |
| 19 | +using namespace cuda::experimental::stf; |
| 20 | + |
| 21 | +int main() |
| 22 | +{ |
| 23 | + stream_ctx ctx; |
| 24 | + |
| 25 | + // Create a 3-level thread hierarchy specification that would expose the bug: |
| 26 | + // Level 0: only 1 device to run on CI |
| 27 | + // Level 1: 4 blocks per device (width 4) |
| 28 | + // Level 2: 64 threads per block (width 64) |
| 29 | + // |
| 30 | + auto spec = par(hw_scope::device, 1, con<4>(hw_scope::block, con<64>(hw_scope::thread))); |
| 31 | + |
| 32 | + int test_result = 0; |
| 33 | + auto l_test_result = ctx.logical_data(make_slice(&test_result, 1)); |
| 34 | + |
| 35 | + ctx.launch(spec, exec_place::current_device(), l_test_result.rw())->*[] __device__(auto th, auto result) { |
| 36 | + if (th.rank() == 0) |
| 37 | + { |
| 38 | + bool level0_correct = (th.size(0) == 1); // device level |
| 39 | + bool level1_correct = (th.size(1) == 1 * 4) && (gridDim.x == 4); // blocks per device |
| 40 | + bool level2_correct = (th.size(2) == 1 * 4 * 64) && (blockDim.x == 64); // threads per block |
| 41 | + |
| 42 | + // Set test result based on whether all levels are correct |
| 43 | + result[0] = level0_correct && level1_correct && level2_correct ? 1 : 0; |
| 44 | + } |
| 45 | + }; |
| 46 | + |
| 47 | + ctx.finalize(); |
| 48 | + |
| 49 | + if (test_result != 1) |
| 50 | + { |
| 51 | + fprintf(stderr, "FAIL: Hierarchy dimensions are incorrect!\n"); |
| 52 | + return 1; |
| 53 | + } |
| 54 | + |
| 55 | + return 0; |
| 56 | +} |
0 commit comments