FasTensor  1.0.0
Transform Supercomputing for AI
ft_type.h
Go to the documentation of this file.
1 
2 
3 /*
4 ****************************
5 
6 FasTensor (FT) Copyright (c) 2021, The Regents of the University of
7 California, through Lawrence Berkeley National Laboratory (subject to
8 receipt of any required approvals from the U.S. Dept. of Energy).
9 All rights reserved.
10 
11 If you have questions about your rights to use or distribute this software,
12 please contact Berkeley Lab's Intellectual Property Office at
14 
15 NOTICE. This Software was developed under funding from the U.S. Department
16 of Energy and the U.S. Government consequently retains certain rights. As
17 such, the U.S. Government has been granted for itself and others acting on
18 its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
19 Software to reproduce, distribute copies to the public, prepare derivative
20 works, and perform publicly and display publicly, and to permit others to do so.
21 
22 
23 ****************************
24 
25 
26 *** License Agreement ***
27 
28 FasTensor (FT) Copyright (c) 2021, The Regents of the University of
29 California, through Lawrence Berkeley National Laboratory (subject to
30 receipt of any required approvals from the U.S. Dept. of Energy).
31 All rights reserved.
32 
33 Redistribution and use in source and binary forms, with or without
34 modification, are permitted provided that the following conditions are met:
35 
36 (1) Redistributions of source code must retain the above copyright notice,
37 this list of conditions and the following disclaimer.
38 
39 (2) Redistributions in binary form must reproduce the above copyright
40 notice, this list of conditions and the following disclaimer in the
41 documentation and/or other materials provided with the distribution.
42 
43 (3) Neither the name of the University of California, Lawrence Berkeley
44 National Laboratory, U.S. Dept. of Energy nor the names of its contributors
45 may be used to endorse or promote products derived from this software
46 without specific prior written permission.
47 
48 
49 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
50 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
53 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 POSSIBILITY OF SUCH DAMAGE.
60 
61 You are under no obligation whatsoever to provide any bug fixes, patches,
62 or upgrades to the features, functionality or performance of the source
63 code ("Enhancements") to anyone; however, if you choose to make your
64 Enhancements available either publicly, or directly to Lawrence Berkeley
65 National Laboratory, without imposing a separate written license agreement
66 for such Enhancements, then you hereby grant the following license: a
67 non-exclusive, royalty-free perpetual license to install, use, modify,
68 prepare derivative works, incorporate into other computer software,
69 distribute, and sublicense such enhancements or derivative works thereof,
70 in binary and source code form.
71 */
72 
82 #ifndef ARRAY_UDF_TYPE_H
83 #define ARRAY_UDF_TYPE_H
84 
85 #include <type_traits>
86 #include <iostream>
87 #include <variant>
88 #include <complex>
89 
90 #if __cplusplus > 201402L
91 #include "cista.h"
92 #endif
93 
94 typedef enum AuEndpointType
95 {
96  EP_HDF5 = 0, //from/to HDF5
97  EP_PNETCDF = 1, //from/to NETCDF; todo
98  EP_ADIOS = 2, //from/to AUDIOS; todo
99  EP_BINARY = 3, //from/to binary file; todo
100  EP_VIRTUAL = 4, //from/to Virtual array of above types; todo
101  EP_MEMORY = 5, //from/to in-memory cache: todo
102  EP_H5VDS = 6, //H5 VDS: todo
103  EP_DIR = 7, //Directory to data to process. file format to be detected
104  EP_DASSA = 8, //customized DASSA IO
105  EP_TDMS = 9, //tdms file format (to binary file)
113 AuEndpointType MapString2EndpointType(std::string endpoint_type_str);
114 
115 //See https://support.hdfgroup.org/ftp/HDF5/current/src/unpacked/src/H5Tpublic.h
116 //for reference
117 typedef enum AuEndpointDataType
118 {
120  AU_SHORT = 0,
121  AU_INT = 1,
122  AU_LONG = 2,
125  AU_UINT = 5,
126  AU_ULONG = 6,
128  AU_FLOAT = 8,
130  AU_DOUBLE_COMPLEX = 10, //it is std::complex<double>
131  AU_STRING = 11, //mostly used to store attribute
132  AU_NCLASSES /*this must be last */
134 
137 
142 using AuEndpointDataTypeUnion = std::variant<short, int, long, long long, unsigned short, unsigned int, unsigned long, unsigned long long, float, double, std::complex<double>, std::string>;
143 
144 template <typename T>
146 {
147  if (std::is_same<T, int>::value)
148  {
149  return AU_INT;
150  }
151  else if (std::is_same<T, short>::value)
152  {
153  return AU_SHORT;
154  }
155  else if (std::is_same<T, long>::value)
156  {
157  return AU_LONG;
158  }
159  else if (std::is_same<T, long long>::value)
160  {
161  return AU_LONG_LONG;
162  }
163  else if (std::is_same<T, unsigned int>::value)
164  {
165  return AU_UINT;
166  }
167  else if (std::is_same<T, unsigned short>::value)
168  {
169  return AU_USHORT;
170  }
171  else if (std::is_same<T, unsigned long>::value)
172  {
173  return AU_ULONG;
174  }
175  else if (std::is_same<T, unsigned long long>::value)
176  {
177  return AU_ULLONG;
178  }
179  else if (std::is_same<T, float>::value)
180  {
181  return AU_FLOAT;
182  }
183  else if (std::is_same<T, double>::value)
184  {
185  return AU_DOUBLE;
186  }
187  else if (std::is_same<T, std::complex<double>>::value)
188  {
189  return AU_DOUBLE_COMPLEX;
190  }
191  else if (std::is_same<T, std::string>::value)
192  {
193  return AU_STRING;
194  }
195  else
196  {
197  return AU_NO_TYPE; //Here it might be User-defined class
198  }
199 }
200 
201 // The "direction" specify how to flat output vector
202 // For example, when running a UDF on a cell (i, j) of a 2D array
203 // flat_direction_index = 0: store result vector in (i : i + vsize, j)
204 // flat_direction_index = 1: store result vector in (i, j: j + vsize)
205 // flat_direction_index = 2: store result vector as new dimension of a 3D array (i, j, 0:vsize)
206 //
207 // vsize = -1, variable size of output vector (determined at runtime)
208 // vsize >= 0, size of output vector (set by the users)
209 //Todo: we can infer "vsize" in futher version
210 // we can also support multiple dimensional vector
212 {
217 
218 template <typename T>
219 struct is_vector : public std::false_type
220 {
221 };
222 
223 template <typename T, typename A>
224 struct is_vector<std::vector<T, A>> : public std::true_type
225 {
226 };
227 
228 //1: vector type
229 //0: other types
230 template <typename T>
232 {
233  return is_vector<T>{};
234 }
235 
236 template <typename T>
237 struct is_vector_vector : public std::false_type
238 {
239 };
240 
241 template <typename T, typename A>
242 struct is_vector_vector<std::vector<std::vector<T, A>>> : public std::true_type
243 {
244 };
245 
246 //1: vector type
247 //0: other types
248 template <typename T>
250 {
251  return is_vector_vector<T>{};
252 }
253 
254 //see more detail in third_party/cista.h
255 #define AU_UDT_INIT(A) FT_UDT_INIT(A)
256 
257 //see more detail in third_party/cista.h
258 #define FT_UDT_INIT(A) \
259  CISTA_PRINTABLE(A) \
260  CISTA_COMPARABLE()
261 #endif
std::variant< short, int, long, long long, unsigned short, unsigned int, unsigned long, unsigned long long, float, double, std::complex< double >, std::string > AuEndpointDataTypeUnion
It should follow the order of above AuEndpointDataType.
Definition: ft_type.h:142
AuEndpointType
Definition: ft_type.h:95
@ EP_MEMORY
Definition: ft_type.h:101
@ EP_ADIOS
Definition: ft_type.h:98
@ EP_H5VDS
Definition: ft_type.h:102
@ EP_DASSA
Definition: ft_type.h:104
@ EP_HDF5
Definition: ft_type.h:96
@ EP_DIR
Definition: ft_type.h:103
@ EP_TDMS
Definition: ft_type.h:105
@ EP_VIRTUAL
Definition: ft_type.h:100
@ EP_BINARY
Definition: ft_type.h:99
@ EP_PNETCDF
Definition: ft_type.h:97
AuEndpointDataType InferDataType()
Definition: ft_type.h:145
AuEndpointDataType FTDataType
Definition: ft_type.h:135
AuEndpointType MapString2EndpointType(std::string endpoint_type_str)
map string typed name of type to AuEndpointType
Definition: ft_type.cpp:83
AuEndpointDataType FTType
Definition: ft_type.h:136
OutputVectorFlatDirection
Definition: ft_type.h:212
@ AU_FLAT_OUTPUT_COL
Definition: ft_type.h:213
@ AU_FLAT_OUTPUT_ROW
Definition: ft_type.h:214
@ AU_FLAT_OUTPUT_NEW
Definition: ft_type.h:215
AuEndpointDataType
Definition: ft_type.h:118
@ AU_LONG
Definition: ft_type.h:122
@ AU_ULLONG
Definition: ft_type.h:127
@ AU_DOUBLE
Definition: ft_type.h:129
@ AU_FLOAT
Definition: ft_type.h:128
@ AU_INT
Definition: ft_type.h:121
@ AU_ULONG
Definition: ft_type.h:126
@ AU_USHORT
Definition: ft_type.h:124
@ AU_LONG_LONG
Definition: ft_type.h:123
@ AU_STRING
Definition: ft_type.h:131
@ AU_NCLASSES
Definition: ft_type.h:132
@ AU_SHORT
Definition: ft_type.h:120
@ AU_DOUBLE_COMPLEX
Definition: ft_type.h:130
@ AU_NO_TYPE
Definition: ft_type.h:119
@ AU_UINT
Definition: ft_type.h:125
bool InferVectorType()
Definition: ft_type.h:231
bool InferVectorVectorType()
Definition: ft_type.h:249
Definition: ft_type.h:238
Definition: ft_type.h:220