FasTensor  1.0.0
Transform Supercomputing for AI
ft_endpoint_binary.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 END_POINT_BINARY_H
83 #define END_POINT_BINARY_H
84 
85 #include "ft_type.h"
86 #include "ft_endpoint.h"
87 #include <string>
88 #include <iostream>
89 #include <vector>
90 #include <math.h>
91 
92 #define BINARY_SET_SIZE 0
93 #define BINARY_ENABLE_TRANSPOSE_ON_READ 1
94 #define BINARY_ENABLE_TRANSPOSE_ON_WRITE 2
95 #define BINARY_DISABLE_TRANSPOSE_ON_READ 3
96 #define BINARY_DISABLE_TRANSPOSE_ON_WRITE 4
97 
98 #define BINARY_ENABLE_TRAN_READ BINARY_ENABLE_TRANSPOSE_ON_READ
99 #define BINARY_ENABLE_TRAN_WRITE BINARY_ENABLE_TRANSPOSE_ON_WRITE
100 #define BINARY_DISABLE_TRAN_READ BINARY_DISABLE_TRANSPOSE_ON_READ
101 #define BINARY_DISABLE_TRAN_WRITE BINARY_DISABLE_TRANSPOSE_ON_WRITE
102 //
103 //I/O layer
104 class EndpointBinary : public Endpoint
105 {
106 private:
107  std::string fn_str;
108  FILE *fp = NULL;
109 
119  std::string model_str = "r";
120 
121  size_t rw_type_size;
122 
123  long int seek_offset = 0; //SEEK_SET: from the beginning of file
124 
125  bool tranpose_on_read_flag = false;
126  bool tranpose_on_write_flag = false;
127 
128  //std::vector<size_t> array_size;
129 public:
135  EndpointBinary(std::string endpoint_info_p)
136  {
137  endpoint_info = endpoint_info_p;
139  SetOpenFlag(false);
141  }
147  {
148  SetOpenFlag(false);
150  }
151 
152  virtual ~EndpointBinary()
153  {
154  Close();
155  }
156 
157  void SetMode(std::string model_str_p)
158  {
159  model_str = model_str_p;
160  }
161 
162  std::string GetMode()
163  {
164  return model_str;
165  }
171  int ExtractMeta() override;
177  int PrintInfo() override;
178 
184  int Create() override;
185 
191  int Open() override;
192 
201  int Read(std::vector<unsigned long long> start, std::vector<unsigned long long> end, void *data) override;
202 
211  int Write(std::vector<unsigned long long> start, std::vector<unsigned long long> end, void *data) override;
212 
218  int Close() override;
219 
220  void Map2MyType() override;
221 
227  int ParseEndpointInfo() override;
228 
233  virtual void UpdateSeekOffset();
234 
240  int Control(int opt_code, std::vector<std::string> &parameter_v) override;
241 
247  FILE *GetFP();
248 
254  void SetSeekOffset(long int seek_offset_p);
255 
262  int MapOpStr2Int(std::string op_cmd_str) override;
263 
270  std::string MapOpInt2Str(int op_int) override;
271 
276  void EnableTranposeOnRead();
281  void EnableTranposeOnWrite();
282 
287  void DisableTranposeOnRead();
288 
293  void DisableTranposeOnWrite();
294 };
295 #endif
Definition: ft_endpoint_binary.h:105
int Close() override
close the end-point
Definition: ft_endpoint_binary.cpp:255
int ExtractMeta() override
extracts metadata, possbile endpoint_ranks/endpoint_dim_size/data_element_type
Definition: ft_endpoint_binary.cpp:84
EndpointBinary()
Construct a new Endpoint in Binary Nothing to do there, can be used as sub-endpoint of directory.
Definition: ft_endpoint_binary.h:146
int Open() override
open the endpoint
Definition: ft_endpoint_binary.cpp:103
void Map2MyType() override
call the finalize to close everything (like call Destractor)
Definition: ft_endpoint_binary.cpp:270
void SetMode(std::string model_str_p)
Definition: ft_endpoint_binary.h:157
int Create() override
create the endpoint
Definition: ft_endpoint_binary.cpp:89
int MapOpStr2Int(std::string op_cmd_str) override
map a op_cmd_str to int as input of SpecialOperator
Definition: ft_endpoint_binary.cpp:437
virtual void UpdateSeekOffset()
update the seek_offset
Definition: ft_endpoint_binary.cpp:333
std::string MapOpInt2Str(int op_int) override
map op_int to string
Definition: ft_endpoint_binary.cpp:463
int Write(std::vector< unsigned long long > start, std::vector< unsigned long long > end, void *data) override
write the data to the end-point
Definition: ft_endpoint_binary.cpp:222
void SetSeekOffset(long int seek_offset_p)
Set the Seek Offset.
Definition: ft_endpoint_binary.cpp:426
virtual ~EndpointBinary()
Definition: ft_endpoint_binary.h:152
std::string GetMode()
Definition: ft_endpoint_binary.h:162
EndpointBinary(std::string endpoint_info_p)
Construct a new EndpointBinary object.
Definition: ft_endpoint_binary.h:135
FILE * GetFP()
Get file point.
Definition: ft_endpoint_binary.cpp:421
int ParseEndpointInfo() override
parse endpoint_info to my own info In binary, it map endpoint_info to filename,
Definition: ft_endpoint_binary.cpp:317
void DisableTranposeOnWrite()
DisableTranposeOnWrite.
Definition: ft_endpoint_binary.cpp:502
int PrintInfo() override
print information about the endpoint
Definition: ft_endpoint_binary.cpp:264
void EnableTranposeOnWrite()
EnableTranposeOnWrite.
Definition: ft_endpoint_binary.cpp:484
void EnableTranposeOnRead()
EnableTranposeOnRead.
Definition: ft_endpoint_binary.cpp:475
int Control(int opt_code, std::vector< std::string > &parameter_v) override
call a special operator on binary endpoint such as OP_SET_BINARY_SIZE
Definition: ft_endpoint_binary.cpp:378
int Read(std::vector< unsigned long long > start, std::vector< unsigned long long > end, void *data) override
read the data from end-point
Definition: ft_endpoint_binary.cpp:137
void DisableTranposeOnRead()
DisableTranposeOnRead.
Definition: ft_endpoint_binary.cpp:493
Define the class for the Endpoint used by ArrayUDF to store the data. It contains basic infomation fo...
Definition: ft_endpoint.h:106
void SetEndpointType(AuEndpointType endpoint_type_p)
Set the Endpoint Type object.
Definition: ft_endpoint.cpp:355
void SetOpenFlag(bool open_flag_p)
Definition: ft_endpoint.cpp:156
std::string endpoint_info
Definition: ft_endpoint.h:109
@ EP_BINARY
Definition: ft_type.h:99