annotate liboffloadmic/runtime/cean_util.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /*
kono
parents:
diff changeset
2 Copyright (c) 2014-2016 Intel Corporation. All Rights Reserved.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 Redistribution and use in source and binary forms, with or without
kono
parents:
diff changeset
5 modification, are permitted provided that the following conditions
kono
parents:
diff changeset
6 are met:
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 * Redistributions of source code must retain the above copyright
kono
parents:
diff changeset
9 notice, this list of conditions and the following disclaimer.
kono
parents:
diff changeset
10 * Redistributions in binary form must reproduce the above copyright
kono
parents:
diff changeset
11 notice, this list of conditions and the following disclaimer in the
kono
parents:
diff changeset
12 documentation and/or other materials provided with the distribution.
kono
parents:
diff changeset
13 * Neither the name of Intel Corporation nor the names of its
kono
parents:
diff changeset
14 contributors may be used to endorse or promote products derived
kono
parents:
diff changeset
15 from this software without specific prior written permission.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
kono
parents:
diff changeset
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
kono
parents:
diff changeset
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
kono
parents:
diff changeset
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
kono
parents:
diff changeset
21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
kono
parents:
diff changeset
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
kono
parents:
diff changeset
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
kono
parents:
diff changeset
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
kono
parents:
diff changeset
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
kono
parents:
diff changeset
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
kono
parents:
diff changeset
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
kono
parents:
diff changeset
28 */
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 #ifndef CEAN_UTIL_H_INCLUDED
kono
parents:
diff changeset
32 #define CEAN_UTIL_H_INCLUDED
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 #include <stdint.h>
kono
parents:
diff changeset
35 #include "offload_util.h"
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 // CEAN expression representation
kono
parents:
diff changeset
38 struct Dim_Desc {
kono
parents:
diff changeset
39 int64_t size; // Length of data type
kono
parents:
diff changeset
40 int64_t lindex; // Lower index
kono
parents:
diff changeset
41 int64_t lower; // Lower section bound
kono
parents:
diff changeset
42 int64_t upper; // Upper section bound
kono
parents:
diff changeset
43 int64_t stride; // Stride
kono
parents:
diff changeset
44 };
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 struct Arr_Desc {
kono
parents:
diff changeset
47 int64_t base; // Base address
kono
parents:
diff changeset
48 int64_t rank; // Rank of array
kono
parents:
diff changeset
49 Dim_Desc dim[1];
kono
parents:
diff changeset
50 };
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 struct CeanReadDim {
kono
parents:
diff changeset
53 int64_t count; // The number of elements in this dimension
kono
parents:
diff changeset
54 int64_t size; // The number of bytes between successive
kono
parents:
diff changeset
55 // elements in this dimension.
kono
parents:
diff changeset
56 };
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 struct CeanReadRanges {
kono
parents:
diff changeset
59 Arr_Desc* arr_desc;
kono
parents:
diff changeset
60 void * ptr;
kono
parents:
diff changeset
61 int64_t current_number; // the number of ranges read
kono
parents:
diff changeset
62 int64_t range_max_number; // number of contiguous ranges
kono
parents:
diff changeset
63 int64_t range_size; // size of max contiguous range
kono
parents:
diff changeset
64 int last_noncont_ind; // size of Dim array
kono
parents:
diff changeset
65 int64_t init_offset; // offset of 1-st element from array left bound
kono
parents:
diff changeset
66 CeanReadDim Dim[1];
kono
parents:
diff changeset
67 };
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 struct IntervalDesc {
kono
parents:
diff changeset
70 int64_t lower; // Lower index
kono
parents:
diff changeset
71 int64_t size; // Size of each element at this interval
kono
parents:
diff changeset
72 };
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 struct NonContigDesc {
kono
parents:
diff changeset
75 int64_t base; // Base address
kono
parents:
diff changeset
76 int64_t interval_cnt; // Number of intervals
kono
parents:
diff changeset
77 struct IntervalDesc interval[1];
kono
parents:
diff changeset
78 };
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 // array descriptor length
kono
parents:
diff changeset
81 #define __arr_desc_length(rank) \
kono
parents:
diff changeset
82 (sizeof(int64_t) + sizeof(Dim_Desc) * (rank))
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 // returns offset and length of the data to be transferred
kono
parents:
diff changeset
85 DLL_LOCAL void __arr_data_offset_and_length(const Arr_Desc *adp,
kono
parents:
diff changeset
86 int64_t &offset,
kono
parents:
diff changeset
87 int64_t &length);
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 // define if data array described by argument is contiguous one
kono
parents:
diff changeset
90 DLL_LOCAL bool is_arr_desc_contiguous(const Arr_Desc *ap);
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 // allocate element of CeanReadRanges type initialized
kono
parents:
diff changeset
93 // to read consequently contiguous ranges described by "ap" argument
kono
parents:
diff changeset
94 DLL_LOCAL CeanReadRanges * init_read_ranges_arr_desc(const Arr_Desc *ap);
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 // check if ranges described by 1 argument could be transferred into ranges
kono
parents:
diff changeset
97 // described by 2-nd one
kono
parents:
diff changeset
98 DLL_LOCAL bool cean_ranges_match(
kono
parents:
diff changeset
99 CeanReadRanges * read_rng1,
kono
parents:
diff changeset
100 CeanReadRanges * read_rng2
kono
parents:
diff changeset
101 );
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 // first argument - returned value by call to init_read_ranges_arr_desc.
kono
parents:
diff changeset
104 // returns true if offset and length of next range is set successfuly.
kono
parents:
diff changeset
105 // returns false if the ranges is over.
kono
parents:
diff changeset
106 DLL_LOCAL bool get_next_range(
kono
parents:
diff changeset
107 CeanReadRanges * read_rng,
kono
parents:
diff changeset
108 int64_t *offset
kono
parents:
diff changeset
109 );
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 // returns number of transferred bytes
kono
parents:
diff changeset
112 DLL_LOCAL int64_t cean_get_transf_size(CeanReadRanges * read_rng);
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 #if OFFLOAD_DEBUG > 0
kono
parents:
diff changeset
115 // prints array descriptor contents to stderr
kono
parents:
diff changeset
116 DLL_LOCAL void __arr_desc_dump(
kono
parents:
diff changeset
117 const char *spaces,
kono
parents:
diff changeset
118 const char *name,
kono
parents:
diff changeset
119 const Arr_Desc *adp,
kono
parents:
diff changeset
120 bool dereference,
kono
parents:
diff changeset
121 bool print_values);
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 DLL_LOCAL void noncont_struct_dump(
kono
parents:
diff changeset
124 const char *spaces,
kono
parents:
diff changeset
125 const char *name,
kono
parents:
diff changeset
126 struct NonContigDesc *desc_p);
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 DLL_LOCAL int64_t get_noncont_struct_size(struct NonContigDesc *desc_p);
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 #define ARRAY_DESC_DUMP(spaces, name, adp, dereference, print_values) \
kono
parents:
diff changeset
131 if (console_enabled >= 2) \
kono
parents:
diff changeset
132 __arr_desc_dump(spaces, name, adp, dereference, print_values);
kono
parents:
diff changeset
133 #else
kono
parents:
diff changeset
134 #define ARRAY_DESC_DUMP(spaces, name, adp, dereference, print_values)
kono
parents:
diff changeset
135 #endif // OFFLOAD_DEBUG
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 #endif // CEAN_UTIL_H_INCLUDED