alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
api.hpp
Go to the documentation of this file.
1/* Copyright 2024 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5
6#pragma once
7
15
16#include <algorithm>
17#include <type_traits>
18
19namespace alpaka
20{
21 /** provides the API used during the execution of the current code path
22 *
23 * @attention if api::host os returned it can also mean that this method was called within the host controlling
24 * workflow and not within a kernel running on a CPU device.
25 */
26 constexpr auto thisApi()
27 {
28#if ALPAKA_LANG_SYCL && ALPAKA_LANG_ONEAPI && defined(__SYCL_DEVICE_ONLY__)
29 return api::oneApi;
30#elif ALPAKA_LANG_CUDA && (ALPAKA_COMP_CLANG_CUDA || ALPAKA_COMP_NVCC) && __CUDA_ARCH__
31 return api::cuda;
32#elif ALPAKA_LANG_HIP && defined(__HIP_DEVICE_COMPILE__) && __HIP_DEVICE_COMPILE__ == 1
33 return api::hip;
34#else
35 return api::host;
36#endif
37 }
38
39 namespace onHost
40 {
41 constexpr auto apis = std::make_tuple(api::host, api::cuda, api::hip, api::oneApi);
42
43 constexpr auto enabledApis = meta::filter([](auto api) constexpr { return isPlatformAvaiable(api); }, apis);
44 } // namespace onHost
45
46 namespace api
47 {
48 constexpr bool operator==(alpaka::concepts::Api auto lhs, alpaka::concepts::Api auto rhs)
49 {
50 return std::is_same_v<ALPAKA_TYPEOF(lhs), ALPAKA_TYPEOF(rhs)>;
51 }
52
53 constexpr bool operator!=(alpaka::concepts::Api auto lhs, alpaka::concepts::Api auto rhs)
54 {
55 return !(lhs == rhs);
56 }
57 } // namespace api
58} // namespace alpaka
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:154
Concept to check for APIs.
Definition api.hpp:42
constexpr auto oneApi
Definition Api.hpp:29
constexpr auto hip
Definition Api.hpp:41
constexpr auto cuda
Definition Api.hpp:41
constexpr auto host
Definition Api.hpp:39
constexpr bool operator!=(alpaka::concepts::Api auto lhs, alpaka::concepts::Api auto rhs)
Definition api.hpp:53
constexpr bool operator==(alpaka::concepts::Api auto lhs, alpaka::concepts::Api auto rhs)
Definition api.hpp:48
constexpr auto filter(auto const unaryConditionFn, auto const list)
Definition filter.hpp:13
Functionality which is usable on the host CPU controller thread.
Definition api.hpp:40
constexpr auto enabledApis
Definition api.hpp:43
constexpr auto apis
Definition api.hpp:41
consteval bool isPlatformAvaiable(alpaka::concepts::Api auto api)
Definition trait.hpp:145
main alpaka namespace.
Definition alpaka.hpp:76
constexpr auto thisApi()
provides the API used during the execution of the current code path
Definition api.hpp:26