STORMM Source Documentation
Loading...
Searching...
No Matches
stormm_vector_types.h
1// -*-c++-*-
2#ifndef STORMM_VECTOR_TYPES_H
3#define STORMM_VECTOR_TYPES_H
4
5#include <cstddef>
6#include <typeinfo>
7#include <typeindex>
8#include <vector>
9#ifdef STORMM_USE_HPC
10#include <vector_types.h>
11#endif
12#include "copyright.h"
13#include "Reporting/error_format.h"
14#include "common_types.h"
15
16namespace stormm {
17namespace data_types {
18
19#ifndef STORMM_USE_HPC
20// If CUDA is not defined, then some of the CUDA POD vector types will need to be delineated in
21// order to run the program in CPU code.
22struct int2 {
23 int x;
24 int y;
25};
26
27struct int3 {
28 int x;
29 int y;
30 int z;
31};
32
33struct int4 {
34 int x;
35 int y;
36 int z;
37 int w;
38};
39
40struct uint2 {
41 unsigned int x;
42 unsigned int y;
43};
44
45struct uint3 {
46 unsigned int x;
47 unsigned int y;
48 unsigned int z;
49};
50
51struct uint4 {
52 unsigned int x;
53 unsigned int y;
54 unsigned int z;
55 unsigned int w;
56};
57
58struct float2 {
59 float x;
60 float y;
61};
62
63struct float3 {
64 float x;
65 float y;
66 float z;
67};
68
69struct float4 {
70 float x;
71 float y;
72 float z;
73 float w;
74};
75
76struct longlong2 {
77 long long int x;
78 long long int y;
79};
80
81struct longlong3 {
82 long long int x;
83 long long int y;
84 long long int z;
85};
86
87struct longlong4 {
88 long long int x;
89 long long int y;
90 long long int z;
91 long long int w;
92};
93
94struct ulonglong2 {
95 unsigned long long int x;
96 unsigned long long int y;
97};
98
99struct ulonglong3 {
100 unsigned long long int x;
101 unsigned long long int y;
102 unsigned long long int z;
103};
104
106 unsigned long long int x;
107 unsigned long long int y;
108 unsigned long long int z;
109 unsigned long long int w;
110};
111
112struct double2 {
113 double x;
114 double y;
115};
116
117struct double3 {
118 double x;
119 double y;
120 double z;
121};
122
123struct double4 {
124 double x;
125 double y;
126 double z;
127 double w;
128};
129
130struct char2 {
131 char x;
132 char y;
133};
134
135struct char3 {
136 char x;
137 char y;
138 char z;
139};
140
141struct char4 {
142 char x;
143 char y;
144 char z;
145 char w;
146};
147
148struct uchar2 {
149 unsigned char x;
150 unsigned char y;
151};
152
153struct uchar3 {
154 unsigned char x;
155 unsigned char y;
156 unsigned char z;
157};
158
159struct uchar4 {
160 unsigned char x;
161 unsigned char y;
162 unsigned char z;
163 unsigned char w;
164};
165
166struct short2 {
167 short int x;
168 short int y;
169};
170
171struct short3 {
172 short int x;
173 short int y;
174 short int z;
175};
176
177struct short4 {
178 short int x;
179 short int y;
180 short int z;
181 short int w;
182};
183
184struct ushort2 {
185 unsigned short int x;
186 unsigned short int y;
187};
188
189struct ushort3 {
190 unsigned short int x;
191 unsigned short int y;
192 unsigned short int z;
193};
194
195struct ushort4 {
196 unsigned short int x;
197 unsigned short int y;
198 unsigned short int z;
199 unsigned short int w;
200};
201
202#endif
203
204// Type definitions for consistent nomenclature
205typedef longlong2 llint2;
206typedef longlong3 llint3;
207typedef longlong4 llint4;
208typedef ulonglong2 ullint2;
209typedef ulonglong3 ullint3;
210typedef ulonglong4 ullint4;
211
212// CUDA- and HIP-defined vector types corresponding to each of the above POD types
213static const size_t int2_type_index = std::type_index(typeid(int2)).hash_code();
214static const size_t int3_type_index = std::type_index(typeid(int3)).hash_code();
215static const size_t int4_type_index = std::type_index(typeid(int4)).hash_code();
216static const size_t double2_type_index = std::type_index(typeid(double2)).hash_code();
217static const size_t double3_type_index = std::type_index(typeid(double3)).hash_code();
218static const size_t double4_type_index = std::type_index(typeid(double4)).hash_code();
219static const size_t float2_type_index = std::type_index(typeid(float2)).hash_code();
220static const size_t float3_type_index = std::type_index(typeid(float3)).hash_code();
221static const size_t float4_type_index = std::type_index(typeid(float4)).hash_code();
222static const size_t char2_type_index = std::type_index(typeid(char2)).hash_code();
223static const size_t char3_type_index = std::type_index(typeid(char3)).hash_code();
224static const size_t char4_type_index = std::type_index(typeid(char4)).hash_code();
225static const size_t uchar2_type_index = std::type_index(typeid(uchar2)).hash_code();
226static const size_t uchar3_type_index = std::type_index(typeid(uchar3)).hash_code();
227static const size_t uchar4_type_index = std::type_index(typeid(uchar4)).hash_code();
228static const size_t uint2_type_index = std::type_index(typeid(uint2)).hash_code();
229static const size_t uint3_type_index = std::type_index(typeid(uint3)).hash_code();
230static const size_t uint4_type_index = std::type_index(typeid(uint4)).hash_code();
231static const size_t longlong2_type_index = std::type_index(typeid(longlong2)).hash_code();
232static const size_t longlong3_type_index = std::type_index(typeid(longlong3)).hash_code();
233static const size_t longlong4_type_index = std::type_index(typeid(longlong4)).hash_code();
234static const size_t ulonglong2_type_index = std::type_index(typeid(ulonglong2)).hash_code();
235static const size_t ulonglong3_type_index = std::type_index(typeid(ulonglong3)).hash_code();
236static const size_t ulonglong4_type_index = std::type_index(typeid(ulonglong4)).hash_code();
237static const size_t short2_type_index = std::type_index(typeid(short2)).hash_code();
238static const size_t short3_type_index = std::type_index(typeid(short3)).hash_code();
239static const size_t short4_type_index = std::type_index(typeid(short4)).hash_code();
240static const size_t ushort2_type_index = std::type_index(typeid(ushort2)).hash_code();
241static const size_t ushort3_type_index = std::type_index(typeid(ushort3)).hash_code();
242static const size_t ushort4_type_index = std::type_index(typeid(ushort4)).hash_code();
243
245template <typename T> bool isHpcVectorType();
246
248template <typename T> bool isSignedIntegralHpcVectorType();
249
251template <typename T> bool isUnsignedIntegralHpcVectorType();
252
254template <typename T> bool isFloatingPointHpcVectorType();
255
257template <typename T> int getHpcVectorTypeSize();
258
260template <typename T> std::string getStormmHpcVectorTypeName();
261
265struct int95_t {
266 long long int x;
269 int y;
270};
271
272// Also define the fixed-precision type for 95-bit storage of double-precision numbers.
273static const size_t int95t_type_index = std::type_index(typeid(int95_t)).hash_code();
274
277template <typename T> struct Vec2 {
278
281 explicit Vec2(T x_in, T y_in);
282 template <typename Tinput> Vec2(const Tinput v_in);
284
285 // Public member variables
286 T x;
287 T y;
288};
289
292template <typename T> struct Vec3 {
293
296 explicit Vec3(T x_in, T y_in, T z_in);
297 template <typename Tinput> Vec3(const Tinput v_in);
299
300 T x;
301 T y;
302 T z;
303};
304
307template <typename T> struct Vec4 {
308
311 explicit Vec4(T x_in, T y_in, T z_in, T w_in);
312 template <typename Tinput> Vec4(const Tinput v_in);
314
315 T x;
316 T y;
317 T z;
318 T w;
319};
320
332template <typename T> double2 vtConv2(const T rhs);
333template <typename T> double3 vtConv3(const T rhs);
334template <typename T> double4 vtConv4(const T rhs);
335template <typename T> float2 vtConv2f(const T rhs);
336template <typename T> float3 vtConv3f(const T rhs);
337template <typename T> float4 vtConv4f(const T rhs);
338template <typename T> std::vector<double2> vtConv2(const std::vector<T> &rhs);
339template <typename T> std::vector<double3> vtConv3(const std::vector<T> &rhs);
340template <typename T> std::vector<double4> vtConv4(const std::vector<T> &rhs);
341template <typename T> std::vector<float2> vtConv2f(const std::vector<T> &rhs);
342template <typename T> std::vector<float3> vtConv3f(const std::vector<T> &rhs);
343template <typename T> std::vector<float4> vtConv4f(const std::vector<T> &rhs);
345
350uint short2ToUint(const short2 ituple);
351uint ushort2ToUint(const ushort2 ituple);
352uint char4ToUint(const char4 ctuple);
353uint uchar4ToUint(const uchar4 ctuple);
355
360short2 uintToShort2(const uint val);
361ushort2 uintToUshort2(const uint val);
362char4 uintToChar4(const uint val);
363uchar4 uintToUchar4(const uint val);
365
371bool operator==(const short2 lhs, const short2 rhs);
372bool operator!=(const short2 lhs, const short2 rhs);
373bool operator==(const short3 lhs, const short3 rhs);
374bool operator!=(const short3 lhs, const short3 rhs);
375bool operator==(const short4 lhs, const short4 rhs);
376bool operator!=(const short4 lhs, const short4 rhs);
377
378bool operator==(const ushort2 lhs, const ushort2 rhs);
379bool operator!=(const ushort2 lhs, const ushort2 rhs);
380bool operator==(const ushort3 lhs, const ushort3 rhs);
381bool operator!=(const ushort3 lhs, const ushort3 rhs);
382bool operator==(const ushort4 lhs, const ushort4 rhs);
383bool operator!=(const ushort4 lhs, const ushort4 rhs);
384
385bool operator==(const int2 lhs, const int2 rhs);
386bool operator!=(const int2 lhs, const int2 rhs);
387bool operator==(const int3 lhs, const int3 rhs);
388bool operator!=(const int3 lhs, const int3 rhs);
389bool operator==(const int4 lhs, const int4 rhs);
390bool operator!=(const int4 lhs, const int4 rhs);
391
392bool operator==(const uint2 lhs, const uint2 rhs);
393bool operator!=(const uint2 lhs, const uint2 rhs);
394bool operator==(const uint3 lhs, const uint3 rhs);
395bool operator!=(const uint3 lhs, const uint3 rhs);
396bool operator==(const uint4 lhs, const uint4 rhs);
397bool operator!=(const uint4 lhs, const uint4 rhs);
398
399bool operator==(const llint2 lhs, const llint2 rhs);
400bool operator!=(const llint2 lhs, const llint2 rhs);
401bool operator==(const llint3 lhs, const llint3 rhs);
402bool operator!=(const llint3 lhs, const llint3 rhs);
403bool operator==(const llint4 lhs, const llint4 rhs);
404bool operator!=(const llint4 lhs, const llint4 rhs);
405
406bool operator==(const ullint2 lhs, const ullint2 rhs);
407bool operator!=(const ullint2 lhs, const ullint2 rhs);
408bool operator==(const ullint3 lhs, const ullint3 rhs);
409bool operator!=(const ullint3 lhs, const ullint3 rhs);
410bool operator==(const ullint4 lhs, const ullint4 rhs);
411bool operator!=(const ullint4 lhs, const ullint4 rhs);
412
413bool operator<(const char4 lhs, const char4 rhs);
414bool operator<=(const char4 lhs, const char4 rhs);
415bool operator>(const char4 lhs, const char4 rhs);
416bool operator>=(const char4 lhs, const char4 rhs);
417bool operator==(const char4 lhs, const char4 rhs);
418bool operator!=(const char4 lhs, const char4 rhs);
420
424 short si;
425 ushort usi;
426 char2 c2;
427 uchar2 uc2;
428};
429
431 int i;
432 uint ui;
433 float f;
434 char4 c4;
435 uchar4 uc4;
436};
437
439 llint lli;
440 ullint ulli;
441 double d;
442 int2 i2;
443 uint2 ui2;
444 float2 f2;
445};
446
447
448} // namespace data_types
449} // namespace stormm
450
451#include "stormm_vector_types.tpp"
452
453namespace stormm {
454
455// Make the HPC vectorized tuple types available through STORMM namespaces, if they were defined
456// without an overarching HPC library.
457#ifndef STORMM_USE_HPC
458using data_types::int2;
459using data_types::int3;
460using data_types::int4;
461using data_types::double2;
462using data_types::double3;
463using data_types::double4;
464using data_types::float2;
465using data_types::float3;
466using data_types::float4;
467using data_types::char2;
468using data_types::char3;
469using data_types::char4;
470using data_types::uchar2;
471using data_types::uchar3;
472using data_types::uchar4;
473using data_types::uint2;
474using data_types::uint3;
475using data_types::uint4;
476using data_types::longlong2;
477using data_types::longlong3;
478using data_types::longlong4;
479using data_types::ulonglong2;
480using data_types::ulonglong3;
481using data_types::ulonglong4;
482using data_types::short2;
483using data_types::short3;
484using data_types::short4;
485using data_types::ushort2;
486using data_types::ushort3;
487using data_types::ushort4;
488#endif
489
490// Alternate type definitions need to be carried through regardless of HPC compilation
491using data_types::llint2;
492using data_types::llint3;
493using data_types::llint4;
494using data_types::ullint2;
495using data_types::ullint3;
496using data_types::ullint4;
497
498// Also make the int95_t data type generally available by including this header file.
499using data_types::int95_t;
500
501// Make type index identifiers available in all STORMM namespaces
502using data_types::int2_type_index;
503using data_types::int3_type_index;
504using data_types::int4_type_index;
505using data_types::double2_type_index;
506using data_types::double3_type_index;
507using data_types::double4_type_index;
508using data_types::float2_type_index;
509using data_types::float3_type_index;
510using data_types::float4_type_index;
511using data_types::char2_type_index;
512using data_types::char3_type_index;
513using data_types::char4_type_index;
514using data_types::uchar2_type_index;
515using data_types::uchar3_type_index;
516using data_types::uchar4_type_index;
517using data_types::uint2_type_index;
518using data_types::uint3_type_index;
519using data_types::uint4_type_index;
520using data_types::longlong2_type_index;
521using data_types::longlong3_type_index;
522using data_types::longlong4_type_index;
523using data_types::ulonglong2_type_index;
524using data_types::ulonglong3_type_index;
525using data_types::ulonglong4_type_index;
526using data_types::short2_type_index;
527using data_types::short3_type_index;
528using data_types::short4_type_index;
529using data_types::ushort2_type_index;
530using data_types::ushort3_type_index;
531using data_types::ushort4_type_index;
532using data_types::int95t_type_index;
533
534// Template-compatible vector types for C++ code
535using data_types::Vec2;
536using data_types::Vec3;
537using data_types::Vec4;
538
539// Templated conversion functions for getting anything of the right tuple complexity into a float
540// or double tuple
541using data_types::vtConv2;
542using data_types::vtConv3;
543using data_types::vtConv4;
544using data_types::vtConv2f;
545using data_types::vtConv3f;
546using data_types::vtConv4f;
547using data_types::short2ToUint;
548using data_types::ushort2ToUint;
549using data_types::char4ToUint;
550using data_types::uchar4ToUint;
551using data_types::uintToShort2;
552using data_types::uintToUshort2;
553using data_types::uintToChar4;
554using data_types::uintToUchar4;
555
557using data_types::Ecumenical2;
558using data_types::Ecumenical4;
559using data_types::Ecumenical8;
560
561// Overloaded assignment and comparison operators
562using data_types::operator<;
563using data_types::operator<=;
564using data_types::operator>;
565using data_types::operator>=;
566using data_types::operator==;
567using data_types::operator!=;
568
569} // namespace stormm
570
571#endif
Vec2(T x_in, T y_in)
Constructors will accept two scalars or one of the defined vector tuples.
T y
The second member, equivalent to the y member of a float2 or longlong2 tuple.
Definition stormm_vector_types.h:287
T x
The first member, equivalent to the x member of a float2 or longlong2 tuple.
Definition stormm_vector_types.h:286
T y
The second member, equivalent to the y member of a double3 or uint3 tuple.
Definition stormm_vector_types.h:301
Vec3(T x_in, T y_in, T z_in)
Constructors will accept three scalars or one of the defined vector tuples.
T z
The third member, equivalent to the z member of a double3 or uint3 tuple.
Definition stormm_vector_types.h:302
T x
The first member, equivalent to the x member of a double3 or uint3 tuple.
Definition stormm_vector_types.h:300
T w
The fourth member, equivalent to the w member of a float4 or int4 tuple.
Definition stormm_vector_types.h:318
T x
The first member, equivalent to the x member of a float4 or int4 tuple.
Definition stormm_vector_types.h:315
Vec4(T x_in, T y_in, T z_in, T w_in)
Constructors will accept four scalars or one of the defined vector tuples.
T z
The third member, equivalent to the z member of a float4 or int4 tuple.
Definition stormm_vector_types.h:317
T y
The second member, equivalent to the y member of a float4 or int4 tuple.
Definition stormm_vector_types.h:316
Definition stormm_vector_types.h:130
Definition stormm_vector_types.h:135
Definition stormm_vector_types.h:141
Definition stormm_vector_types.h:112
Definition stormm_vector_types.h:117
Definition stormm_vector_types.h:123
Definition stormm_vector_types.h:58
Definition stormm_vector_types.h:63
Definition stormm_vector_types.h:69
Definition stormm_vector_types.h:22
Definition stormm_vector_types.h:27
Definition stormm_vector_types.h:33
A mixed tuple for 95-bit integer accumulation. This is the proper way to take double-precision floati...
Definition stormm_vector_types.h:265
int y
Overflow accumulator, used when the primary value would be exceeded.
Definition stormm_vector_types.h:269
long long int x
Definition stormm_vector_types.h:266
Definition stormm_vector_types.h:76
Definition stormm_vector_types.h:81
Definition stormm_vector_types.h:87
Definition stormm_vector_types.h:166
Definition stormm_vector_types.h:171
Definition stormm_vector_types.h:177
Definition stormm_vector_types.h:148
Definition stormm_vector_types.h:153
Definition stormm_vector_types.h:159
Definition stormm_vector_types.h:40
Definition stormm_vector_types.h:45
Definition stormm_vector_types.h:51
Definition stormm_vector_types.h:94
Definition stormm_vector_types.h:99
Definition stormm_vector_types.h:105
Definition stormm_vector_types.h:184
Definition stormm_vector_types.h:189
Definition stormm_vector_types.h:195
Mimic critical CUDA typecasting intrinsics with simple unions {.
Definition stormm_vector_types.h:423
Definition stormm_vector_types.h:430
Definition stormm_vector_types.h:438