alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
DeviceProperties.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
8#include "alpaka/Vec.hpp"
9
10#include <array>
11#include <cstdint>
12#include <functional>
13#include <ostream>
14#include <string>
15
16namespace alpaka::onHost
17{
18 namespace internal
19 {
20 // forward declaration
21 struct GetDeviceProperties;
22 } // namespace internal
23
24 /** Properties of a device
25 *
26 * Collection of static properties of a device.
27 */
29 {
30 auto getName() const
31 {
32 return name;
33 }
34
35 /** The total amount of global device memory in bytes.
36 *
37 * @attention It is **not** the amount of free memory!
38 *
39 * Device memory is the physical memory of the compute device.
40 * On systems with a GPU which is sharing the memory with the host CPU, this value may be equal to the total
41 * amount of system memory.
42 */
44 /** The amount of shared memory per thread block in bytes. */
46 /** The name of the device. */
47 std::string name;
48 /** The number of multiprocessors.*/
50 /** The warp size.
51 *
52 * Number of threads per thread block that are executed in lock-step.
53 */
54 uint32_t warpSize;
55 /** The maximum total number of threads per thread block. */
57
58 /** Maximum number of threads within a thread block for each dimension.
59 *
60 * @attention Do not assume that the limits are equal for any dimension.
61 * The product of two or more dimensions can exceed maxThreadsPerBlock, this will result in an invalid
62 * configuration when used for kernel execution. All values are 32-bit indexes, take care of overflows.
63 *
64 * @tparam T_dim Number of dimensions used for a kernel call.
65 * @return Maximum number of threads within a block, usable for ThreadSpec.
66 */
67 template<uint32_t T_dim>
69 {
70 std::array<uint32_t, T_dim> res;
71 fnMaxThreadsPerBlock(res.data(), T_dim);
72 return {res};
73 }
74
75 /** The maximum total number of blocks within a grid. */
77
78 /** Maximum number of blocks within a grid for each dimension.
79 *
80 * @attention Do not assume that the limits are equal for any dimension.
81 * The product of two or more dimensions can exceed maxBlocksPerGrid, this will result in an invalid
82 * configuration when used for kernel execution. All values are 32-bit indexes, take care of overflows.
83 *
84 * @tparam T_dim Number of dimensions used for a kernel call.
85 * @return Maximum number of blocks, usable for ThreadSpec.
86 */
87 template<uint32_t T_dim>
89 {
90 std::array<uint32_t, T_dim> res;
91 fnMaxBlocksPerGrid(res.data(), T_dim);
92 return {res};
93 }
94
95 private:
96 friend internal::GetDeviceProperties;
97
98 /** function to fill maximum number of threads per block per dimension
99 *
100 * result: pointer to vector data, follows alpaka index order
101 * numDims: number of dimensions of the result, elements in result
102 */
103 std::function<void(uint32_t* result, uint32_t numDims)> fnMaxThreadsPerBlock;
104
105 /** function to fill maximum number of blocks within a grid per dimension
106 *
107 * result: pointer to vector data, follows alpaka index order
108 * numDims: number of dimensions of the result, elements in result
109 */
110 std::function<void(uint32_t* result, uint32_t numDims)> fnMaxBlocksPerGrid;
111 };
112
113 inline std::ostream& operator<<(std::ostream& s, DeviceProperties const& p)
114 {
115 s << "name: " << p.name << "\n";
116 s << "multiProcessorCount: " << p.multiProcessorCount << "\n";
117 s << "warpSize: " << p.warpSize << "\n";
118 s << "maxThreadsPerBlock: " << p.maxThreadsPerBlock << "\n";
119 s << "maxBlocksPerGrid: " << p.maxBlocksPerGrid << "\n";
120 s << "globalMemCapacityBytes: " << p.globalMemCapacityBytes << "\n";
121 s << "sharedMemPerBlockBytes: " << p.sharedMemPerBlockBytes << "\n";
122 return s;
123 };
124} // namespace alpaka::onHost
Functionality which is usable on the host CPU controller thread.
Definition api.hpp:40
std::ostream & operator<<(std::ostream &s, DeviceProperties const &p)
Vec< uint32_t, T_dim > getMaxBlocksPerGrid() const
Maximum number of blocks within a grid for each dimension.
Vec< uint32_t, T_dim > getMaxThreadsPerBlock() const
Maximum number of threads within a thread block for each dimension.
uint32_t maxThreadsPerBlock
The maximum total number of threads per thread block.
uint32_t multiProcessorCount
The number of multiprocessors.
uint32_t maxBlocksPerGrid
The maximum total number of blocks within a grid.
size_t globalMemCapacityBytes
The total amount of global device memory in bytes.
std::string name
The name of the device.
uint32_t sharedMemPerBlockBytes
The amount of shared memory per thread block in bytes.