25 template<alpaka::concepts::DeviceKind T_DeviceKind>
26 struct Platform : std::enable_shared_from_this<Platform<T_DeviceKind>>
40 static_assert(internal::concepts::Platform<Platform>);
43 std::vector<std::weak_ptr<cpu::Device<Platform>>> devices;
44 std::mutex deviceGuard;
46 std::shared_ptr<Platform> getSharedPtr()
48 return this->shared_from_this();
51 friend struct alpaka::internal::GetName;
55 return "host::Platform";
58 friend struct internal::GetDeviceCount;
60 uint32_t getDeviceCount()
62 uint32_t devCount = 0u;
64 constexpr bool isSupportedDev = trait::IsDeviceSupportedBy::Op<T_DeviceKind, api::Host>::value;
65 if constexpr(isSupportedDev)
69 devCount = alpaka::onHost::internal::hwloc::getNumNumaDomains();
74 if(devices.size() <
static_cast<size_t>(devCount))
76 std::lock_guard<std::mutex> lk{deviceGuard};
77 devices.resize(devCount);
83 friend struct internal::MakeDevice;
88 uint32_t
const numDevices = getDeviceCount();
91 std::stringstream ssErr;
92 ssErr <<
"Unable to return device handle with index " << idx <<
" because there are only "
95 throw std::runtime_error(ssErr.str());
97 std::lock_guard<std::mutex> lk{deviceGuard};
99 if(
auto sharedPtr = devices[idx].lock())
103 auto thisHandle = getSharedPtr();
104 uint32_t numaIdx = internal::hwloc::allNumaDomains;
109 auto newDevice = std::make_shared<cpu::Device<Platform>>(std::move(thisHandle), idx, numaIdx);
110 devices[idx] = newDevice;
114 friend struct internal::GetDeviceProperties;
116 friend struct alpaka::internal::GetDeviceType;
118 T_DeviceKind getDeviceKind()
const
120 return T_DeviceKind{};
127 template<alpaka::concepts::DeviceKind T_DeviceKind>
128 struct MakePlatform::Op<
api::Host, T_DeviceKind>
130 auto operator()(api::Host, T_DeviceKind)
const
136 template<alpaka::concepts::DeviceKind T_DeviceKind>
137 struct GetDeviceProperties::Op<
cpu::Platform<T_DeviceKind>>
139 DeviceProperties operator()(cpu::Platform<T_DeviceKind>
const& platform, uint32_t deviceIdx)
const
141 alpaka::unused(platform);
143 auto prop = DeviceProperties{};
146 prop.multiProcessorCount = hwloc::getNumCores(hwloc::allNumaDomains);
147 prop.globalMemCapacityBytes = hwloc::getMemCapacityBytes(hwloc::allNumaDomains);
153 prop.multiProcessorCount = hwloc::getNumCores(deviceIdx);
154 prop.globalMemCapacityBytes = hwloc::getMemCapacityBytes(deviceIdx);
157 alpaka::unused(deviceIdx);
159 prop.maxThreadsPerBlock = std::numeric_limits<uint32_t>::max();
160 prop.fnMaxThreadsPerBlock = [](uint32_t*
data, uint32_t numDims)
162 for(uint32_t d = 0u; d < numDims; ++d)
163 data[d] = std::numeric_limits<uint32_t>::max();
166 prop.maxBlocksPerGrid = std::numeric_limits<uint32_t>::max();
167 prop.fnMaxBlocksPerGrid = [](uint32_t*
data, uint32_t numDims)
169 for(uint32_t d = 0u; d < numDims; ++d)
170 data[d] = std::numeric_limits<uint32_t>::max();
179namespace alpaka::internal
181 template<alpaka::concepts::DeviceKind T_DeviceKind>
182 struct GetApi::Op<onHost::cpu::Platform<T_DeviceKind>>
184 inline constexpr auto operator()(
auto&& platform)
const
186 alpaka::unused(platform);
#define ALPAKA_BLOCK_SHARED_DYN_MEMBER_ALLOC_KIB
#define ALPAKA_LOG_FUNCTION(logLvl)
Log the entry and exit of a scope.
Functionality which is usable on the host CPU controller thread.
std::shared_ptr< T > Handle
decltype(auto) data(auto &&any)
pointer to data of an object
std::convertible_to< std::string > auto getName(auto &&any)
Runtime name for a given object.
auto make_sharedSingleton(T_Args &&... args)
auto getCpuName() -> std::string
std::convertible_to< std::string > auto getStaticName(auto const &any)
Compile‑time available name for a given object.