alpaka
Abstraction Library for Parallel Kernel Acceleration
PlatformCpu.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Benjamin Worpitz, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
8 #include "alpaka/dev/DevCpu.hpp"
10 
11 #include <sstream>
12 #include <vector>
13 
14 namespace alpaka
15 {
16  //! The CPU device platform.
17  struct PlatformCpu : interface::Implements<ConceptPlatform, PlatformCpu>
18  {
19 #if defined(BOOST_COMP_GNUC) && BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(11, 0, 0) \
20  && BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(12, 0, 0)
21  // This is a workaround for g++-11 bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96295
22  // g++-11 complains in *all* places where a PlatformCpu is used, that it "may be used uninitialized"
23  char c = {};
24 #endif
25  };
26 
27  namespace trait
28  {
29  //! The CPU device device type trait specialization.
30  template<>
32  {
33  using type = DevCpu;
34  };
35 
36  //! The CPU platform device count get trait specialization.
37  template<>
39  {
40  ALPAKA_FN_HOST static auto getDevCount(PlatformCpu const&) -> std::size_t
41  {
43 
44  return 1;
45  }
46  };
47 
48  //! The CPU platform device get trait specialization.
49  template<>
51  {
52  ALPAKA_FN_HOST static auto getDevByIdx(PlatformCpu const& platform, std::size_t const& devIdx) -> DevCpu
53  {
55 
56  std::size_t const devCount = getDevCount(platform);
57  if(devIdx >= devCount)
58  {
59  std::stringstream ssErr;
60  ssErr << "Unable to return device handle for CPU device with index " << devIdx
61  << " because there are only " << devCount << " devices!";
62  throw std::runtime_error(ssErr.str());
63  }
64 
65  return {};
66  }
67  };
68  } // namespace trait
69 } // namespace alpaka
#define ALPAKA_DEBUG_FULL_LOG_SCOPE
Definition: Debug.hpp:62
The CPU device handle.
Definition: DevCpu.hpp:56
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
The alpaka accelerator library.
ALPAKA_FN_HOST auto getDevCount(TPlatform const &platform)
Definition: Traits.hpp:55
The CPU device platform.
Definition: PlatformCpu.hpp:18
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition: Interface.hpp:15
The device type trait.
Definition: Traits.hpp:23
static ALPAKA_FN_HOST auto getDevByIdx(PlatformCpu const &platform, std::size_t const &devIdx) -> DevCpu
Definition: PlatformCpu.hpp:52
The device get trait.
Definition: DevCpu.hpp:41
static ALPAKA_FN_HOST auto getDevCount(PlatformCpu const &) -> std::size_t
Definition: PlatformCpu.hpp:40
The device count get trait.
Definition: Traits.hpp:42