FasTensor  1.0.0
Transform Supercomputing for AI
ft_iarray.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 AU_IARRAY_H
83 #define AU_IARRAY_H
84 
85 #include <vector>
86 #include "ft_type.h"
87 
93 {
94  int rank;
95  std::vector<size_t> count; //Size for each dim
96  std::vector<size_t> offset; //Starting point for each dim
97  std::vector<size_t> row_stride; // rowStride = count
99 
100  iArrayLocal(std::vector<int> &count_p, std::vector<int> &row_stride_p)
101  {
102  count = count_p;
103  row_stride = row_stride_p;
104  rank = count_p.size();
105  offset.resize(rank);
106  for (int i = 0; i < rank; i++)
107  offset[i] = 0;
108  }
109 
110  iArrayLocal(std::vector<int> &count_p, std::vector<int> row_stride_p, std::vector<int> offset_p)
111  {
112  count = count_p;
113  row_stride = row_stride_p;
114  offset = offset_p;
115  rank = count_p.size();
116  }
117 
119  {
120  }
121 };
122 
127 struct iArray
128 {
129  //for portability, they are au_mpi_size_global, au_mpi_rank_global
130  int mpi_size;
131  int mpi_rank;
132 
133  //Global array infomation
134  //Same across all process
137  std::vector<unsigned long long> g_dimension;
138  std::vector<int> g_ghost_size;
139  std::vector<int> g_chunk_size; //g_chunk_size is different from chunK_size of Array in au_array.h
140  //g_chunk_size is the size of local cached data
141  //we only supported regular chunk, i.e., each rank has continious data
142  // and sum(g_dimension/g_chunk_size) = mpi_size
143 
144  //Local array location within the global array
145  //l_start and l_count is the for the data without ghost_size
146  //l_offset is the place to start the
147  std::vector<unsigned long long> l_start;
148  std::vector<unsigned long long> l_count;
149  std::vector<unsigned long long> l_start_ghost; //l_start - g_ghost_size
150  std::vector<unsigned long long> l_count_ghost; //l_start + lount + g_ghost_size
151 
152  //local_array contains data from l_start_ghost to l_count_ghost
154 
155  iArray(std::vector<unsigned long long> &g_dimension_p, std::vector<int> &g_ghost_size_p, std::vector<int> &g_chunk_size_p, int mpi_size_p, int mpi_rank_p)
156  {
157  g_dimension = g_dimension_p;
158  g_ghost_size = g_ghost_size_p;
159  g_chunk_size = g_chunk_size_p;
160  mpi_size = mpi_size_p;
161  mpi_rank = mpi_rank_p;
162  array_rank = g_dimension.size();
163  }
164 };
165 
166 #endif
AuEndpointDataType
Definition: ft_type.h:118
global array
Definition: ft_iarray.h:128
std::vector< int > g_ghost_size
Definition: ft_iarray.h:138
int mpi_rank
Definition: ft_iarray.h:131
std::vector< unsigned long long > l_start
Definition: ft_iarray.h:147
std::vector< int > g_chunk_size
Definition: ft_iarray.h:139
iArray(std::vector< unsigned long long > &g_dimension_p, std::vector< int > &g_ghost_size_p, std::vector< int > &g_chunk_size_p, int mpi_size_p, int mpi_rank_p)
Definition: ft_iarray.h:155
iArrayLocal * local_array
Definition: ft_iarray.h:153
AuEndpointDataType array_data_element_type
Definition: ft_iarray.h:136
int mpi_size
Definition: ft_iarray.h:130
std::vector< unsigned long long > l_start_ghost
Definition: ft_iarray.h:149
std::vector< unsigned long long > l_count
Definition: ft_iarray.h:148
int array_rank
Definition: ft_iarray.h:135
std::vector< unsigned long long > g_dimension
Definition: ft_iarray.h:137
std::vector< unsigned long long > l_count_ghost
Definition: ft_iarray.h:150
array of local data
Definition: ft_iarray.h:93
void * local_array_data
Definition: ft_iarray.h:98
std::vector< size_t > count
Definition: ft_iarray.h:95
int rank
Definition: ft_iarray.h:94
std::vector< size_t > offset
Definition: ft_iarray.h:96
iArrayLocal()
Definition: ft_iarray.h:118
iArrayLocal(std::vector< int > &count_p, std::vector< int > row_stride_p, std::vector< int > offset_p)
Definition: ft_iarray.h:110
iArrayLocal(std::vector< int > &count_p, std::vector< int > &row_stride_p)
Definition: ft_iarray.h:100
std::vector< size_t > row_stride
Definition: ft_iarray.h:97