Debian Codegraph @

offload/unittests/Conformance/device_code/KernelRunner.hpp

raw
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file contains the definition of the runKernelBody, a template helper
11 /// that executes the per-thread logic of a math function's kernel wrapper.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef CONFORMANCE_DEVICE_CODE_KERNELRUNNER_HPP
16 #define CONFORMANCE_DEVICE_CODE_KERNELRUNNER_HPP
17
18 #include <gpuintrin.h>
19 #include <stddef.h>
20 #include <stdint.h>
21
22 namespace kernels {
23
24 template <auto Func, typename OutType, typename... InTypes>
25 void runKernelBody(size_t NumElements, OutType *Out, const InTypes *...Ins) {
26 uint32_t Index =
27 __gpu_num_threads_x() * __gpu_block_id_x() + __gpu_thread_id_x();
28
29 if (Index < NumElements) {
30 Out[Index] = Func(Ins[Index]...);
31 }
32 }
33 } // namespace kernels
34
35 #endif // CONFORMANCE_DEVICE_CODE_KERNELRUNNER_HPP