Logo ROOT  
Reference Guide
SOFIE_common.hxx
Go to the documentation of this file.
1#ifndef TMVA_SOFIE_SOFIE_COMMON
2#define TMVA_SOFIE_SOFIE_COMMON
3
4#include "TMVA/RTensor.hxx"
5#include "TMVA/Types.h"
6
7#include <type_traits>
8#include <cstdint>
9#include <string>
10#include <vector>
11#include <memory>
12#include <regex>
13
14namespace TMVA{
15namespace Experimental{
16namespace SOFIE{
17
18//typedef RTensor tensor_t;
19
20enum class ETensorType{
21 UNDEFINED = 0, FLOAT = 1, UNINT8 = 2, INT8 = 3, UINT16 = 4, INT16 = 5, INT32 = 6, INT64 = 7, STRING = 8, BOOL = 9, //order sensitive
22 FLOAT16 = 10, DOUBLE = 11, UINT32 = 12, UINT64 = 13, COMPLEX64 = 14, COMPLEX28 = 15, BFLOAT16 = 16
23};
24
25typedef std::int64_t int_t;
26
29
30struct Dim{
31 bool isParam = false;
32 size_t dim;
33 std::string param;
34};
35
36std::vector<Dim> ConvertShapeToDim(std::vector<size_t> shape);
37
38
41 std::vector<Dim> shape;
42};
43
46 std::vector<size_t> shape;
47};
48
49std::size_t ConvertShapeToLength(std::vector<size_t> shape);
50
51std::string ConvertShapeToString(std::vector<size_t> shape);
52
55 std::vector<std::size_t> fShape;
56 std::shared_ptr<void> fData; //! Transient
58 char* fPersistentData=nullptr; //[fSize] Persistent
59
61 for(auto item:fShape){
62 fSize*=(Int_t)item;
63 }
64 switch(fType){
65 case ETensorType::FLOAT: fSize*=sizeof(float); break;
66 default:
67 throw std::runtime_error("TMVA::SOFIE doesn't yet supports serialising data-type " + ConvertTypeToString(fType));
68 }
69 fPersistentData=(char*)fData.get();
70 }
72 switch(fType){
73 case ETensorType::FLOAT: {
74 std::shared_ptr<void> tData(malloc(fSize * sizeof(float)), free);
75 std::memcpy(tData.get(), fPersistentData,fSize * sizeof(float));
76 fData=tData;
77 break;
78 }
79 default: {
80 throw std::runtime_error("TMVA::SOFIE doesn't yet supports serialising data-type " + ConvertTypeToString(fType));
81 }
82 }
83 }
84};
85
86template <typename T>
88 if (std::is_same<T, float>::value) return ETensorType::FLOAT;
89 if (std::is_same<T, uint8_t>::value) return ETensorType::UNINT8;
90 if (std::is_same<T, int8_t>::value) return ETensorType::INT8;
91 if (std::is_same<T, uint16_t>::value) return ETensorType::UINT16;
92 if (std::is_same<T, int16_t>::value) return ETensorType::INT16;
93 if (std::is_same<T, int32_t>::value) return ETensorType::INT32;
94 if (std::is_same<T, int64_t>::value) return ETensorType::INT64;
95 if (std::is_same<T, std::string>::value) return ETensorType::STRING;
96 if (std::is_same<T, bool>::value) return ETensorType::BOOL;
97 //float16 unimplemented
98 if (std::is_same<T, double>::value) return ETensorType::DOUBLE;
99 if (std::is_same<T, uint32_t>::value) return ETensorType::UINT32;
100 if (std::is_same<T, uint64_t>::value) return ETensorType::UINT64;
101 //complex 64, 28, bfloat 16 unimplemented
102}
103
104namespace UTILITY{
105template<typename T>
106T* Unidirectional_broadcast(const T* original_data, const std::vector<size_t> original_shape, const std::vector<size_t> target_shape);
107std::string Clean_name(std::string input_tensor_name);
108}
109
110namespace BLAS{
111extern "C" void sgemm_(const char * transa, const char * transb, const int * m, const int * n, const int * k,
112 const float * alpha, const float * A, const int * lda, const float * B, const int * ldb,
113 const float * beta, float * C, const int * ldc);
114}//BLAS
115}//SOFIE
116}//Experimental
117}//TMVA
118
119#endif //TMVA_SOFIE_RMODEL
int Int_t
Definition: RtypesCore.h:45
int type
Definition: TGX11.cxx:121
#define free
Definition: civetweb.c:1539
#define malloc
Definition: civetweb.c:1536
double beta(double x, double y)
Calculates the beta function.
const Int_t n
Definition: legend1.C:16
static double B[]
static double A[]
static double C[]
double T(double x)
Definition: ChebyshevPol.h:34
void sgemm_(const char *transa, const char *transb, const int *m, const int *n, const int *k, const float *alpha, const float *A, const int *lda, const float *B, const int *ldb, const float *beta, float *C, const int *ldc)
std::string Clean_name(std::string input_tensor_name)
T * Unidirectional_broadcast(const T *original_data, const std::vector< size_t > original_shape, const std::vector< size_t > target_shape)
std::vector< Dim > ConvertShapeToDim(std::vector< size_t > shape)
Definition: SOFIE_common.cxx:9
ETensorType GetTemplatedType(T)
std::string ConvertShapeToString(std::vector< size_t > shape)
std::string ConvertTypeToString(ETensorType type)
ETensorType ConvertStringToType(std::string type)
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations
auto * m
Definition: textangle.C:8