80 #ifndef _AU_OUTPUT_VECTOR_H_
81 #define _AU_OUTPUT_VECTOR_H_
84 #include <type_traits>
87 #include <sys/types.h>
113 inline void GetChunkAddress(
const unsigned long long chunk_id,
const std::vector<unsigned long long> array_size,
const std::vector<size_t> chunk_size, std::vector<unsigned long long> &chunk_start_address, std::vector<unsigned long long> &chunk_end_address)
115 int rank = array_size.size();
120 std::vector<unsigned long long> chunks;
121 unsigned long long total_chunks = 1;
124 for (
int i = 0; i < rank; i++)
126 if (array_size[i] % chunk_size[i] == 0)
128 chunks[i] = array_size[i] / chunk_size[i];
132 chunks[i] = array_size[i] / chunk_size[i] + 1;
134 total_chunks = chunks[i] * total_chunks;
137 if (chunk_id >= total_chunks)
139 AU_EXIT(
"chunk_id >= total_chunks: chunk_id =" + std::to_string(chunk_id) +
", total_chunks = " + std::to_string(total_chunks));
141 std::vector<unsigned long long> chunk_coordinate(rank);
148 chunk_start_address.resize(rank);
149 chunk_end_address.resize(rank);
150 for (
int i = 0; i < rank; i++)
153 if (chunk_coordinate[i] * chunk_size[i] < array_size[i])
155 chunk_start_address[i] = chunk_coordinate[i] * chunk_size[i];
159 chunk_start_address[i] = array_size[i];
162 if (chunk_start_address[i] + chunk_size[i] - 1 < array_size[i])
164 chunk_end_address[i] = chunk_start_address[i] + chunk_size[i] - 1;
168 chunk_end_address[i] = array_size[i] - 1;
186 template <
typename T>
187 void *
InsertOutputVV2WriteV(std::vector<std::vector<T>> &v, std::vector<size_t> &v_shape, std::vector<unsigned long long> &write_start_address, std::vector<unsigned long long> &write_end_address,
bool last_chunk_flag, std::vector<size_t> &prev_v_shape)
191 int rank = write_start_address.size();
194 if (v_shape.size() > (rank + 1))
196 AU_INFO(
"Warning: the shape of output Stencil has more dimensions than current support !\n");
199 std::vector<unsigned long long> write_vector_size;
200 unsigned long long write_vector_length = 1, temp_address;
201 for (
int i = 0; i < v_shape.size(); i++)
205 write_start_address.push_back(0);
206 write_end_address.push_back(v_shape[i] - 1);
212 temp_address = write_start_address[i];
215 write_start_address[i] = write_start_address[i] * prev_v_shape[i];
219 write_start_address[i] = write_start_address[i] * v_shape[i];
221 write_end_address[i] = write_start_address[i] + (write_end_address[i] - temp_address + 1) * v_shape[i] - 1;
224 write_vector_size.push_back(write_end_address[i] - write_start_address[i] + 1);
225 write_vector_length = write_vector_length * write_vector_size[i];
229 rank = v_shape.size();
231 T *rv = (T *)malloc(write_vector_length *
sizeof(T));
242 std::vector<unsigned long long> view_start(rank), view_end(rank);
243 for (
size_t i = 0; i < v.size(); i++)
252 template <
typename T>
253 void *
InsertOutputVV2WriteV(std::vector<T> &v, std::vector<size_t> &v_shape, std::vector<unsigned long long> &write_start_address, std::vector<unsigned long long> &write_end_address,
bool last_chunk_flag, std::vector<size_t> &prev_v_shape)
255 AU_EXIT(
"This function should not be called !");
258 template <
typename T>
259 void *
InsertOutputVV2WriteV(T &v, std::vector<size_t> &v_shape, std::vector<unsigned long long> &write_start_address, std::vector<unsigned long long> &write_end_address,
bool last_chunk_flag, std::vector<size_t> &prev_v_shape)
261 AU_EXIT(
"This function should not be called !");
296 template <
typename T>
297 void *
FlatVector(std::vector<std::vector<T>> &v,
OutputVectorFlatDirection direction, std::vector<unsigned long long> &start_address, std::vector<unsigned long long> &end_address,
size_t &v_size)
310 for (
unsigned j = 0; j < v.size() - 1; j++)
312 if (v[j].size() != v[j + 1].size())
314 AU_EXIT(
"Size of each element of vector must be equal.");
317 v_size = v[0].size();
321 start_address.push_back(0);
322 end_address.push_back(v_size - 1);
326 T *rv = (T *)malloc(v.size() * v_size *
sizeof(T));
334 for (
unsigned i = 0; i < v_size; i++)
336 for (
unsigned j = 0; j < v.size(); j++)
338 memcpy(rv + v.size() * i + j, &(v[j][i]),
sizeof(T));
345 for (
unsigned i = 0; i < v.size(); i++)
347 memcpy(rv + v_size * i, &(v[i][0]), v_size *
sizeof(T));
352 AU_EXIT(
"Not supported option yet to flat vector");
355 end_address[direction] = start_address[direction] + (end_address[direction] - start_address[direction] + 1) * v_size - 1;
360 template <
typename T>
366 template <
typename T>
int ArrayViewAccessP(T *view_v, T *array_v, std::vector< unsigned long long > array_size, std::vector< unsigned long long > start, std::vector< unsigned long long > end, int read_write_code)
Definition: ft_array_view_access.h:195
#define ARRAY_VIEW_WRITE
Definition: ft_array_view_access.h:90
void * FlatVector(std::vector< std::vector< T >> &v, OutputVectorFlatDirection direction, std::vector< unsigned long long > &start_address, std::vector< unsigned long long > &end_address, size_t &v_size)
flat vector of vector to 1D vector direction specify row-major or colum major AU_FLAT_OUTPUT_ROW (0):...
Definition: ft_output_vector.h:297
void GetChunkAddress(const unsigned long long chunk_id, const std::vector< unsigned long long > array_size, const std::vector< size_t > chunk_size, std::vector< unsigned long long > &chunk_start_address, std::vector< unsigned long long > &chunk_end_address)
Get the Chunk Address object.
Definition: ft_output_vector.h:113
void * InsertOutputVV2WriteV(std::vector< std::vector< T >> &v, std::vector< size_t > &v_shape, std::vector< unsigned long long > &write_start_address, std::vector< unsigned long long > &write_end_address, bool last_chunk_flag, std::vector< size_t > &prev_v_shape)
Insert output (vector of vector) into a buffer (vector) to write.
Definition: ft_output_vector.h:187
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
#define ROW_MAJOR_ORDER_REVERSE_MACRO(offset, dsize, dsize_len, result_coord_v)
Definition: ft_utility_macro.h:135
#define AU_EXIT(info)
Definition: ft_utility_macro.h:147
#define AU_INFO(info)
Definition: ft_utility_macro.h:154