PR c++/64359
[official-gcc.git] / liboffloadmic / runtime / cean_util.h
blob83140479269b75cd47e5617ec6a0810e285b584c
1 /*
2 Copyright (c) 2014 Intel Corporation. All Rights Reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CEAN_UTIL_H_INCLUDED
32 #define CEAN_UTIL_H_INCLUDED
34 #include <stdint.h>
36 // CEAN expression representation
37 struct dim_desc {
38 int64_t size; // Length of data type
39 int64_t lindex; // Lower index
40 int64_t lower; // Lower section bound
41 int64_t upper; // Upper section bound
42 int64_t stride; // Stride
45 struct arr_desc {
46 int64_t base; // Base address
47 int64_t rank; // Rank of array
48 dim_desc dim[1];
51 struct CeanReadDim {
52 int64_t count; // The number of elements in this dimension
53 int64_t size; // The number of bytes between successive
54 // elements in this dimension.
57 struct CeanReadRanges {
58 void * ptr;
59 int64_t current_number; // the number of ranges read
60 int64_t range_max_number; // number of contiguous ranges
61 int64_t range_size; // size of max contiguous range
62 int last_noncont_ind; // size of Dim array
63 int64_t init_offset; // offset of 1-st element from array left bound
64 CeanReadDim Dim[1];
67 // array descriptor length
68 #define __arr_desc_length(rank) \
69 (sizeof(int64_t) + sizeof(dim_desc) * (rank))
71 // returns offset and length of the data to be transferred
72 void __arr_data_offset_and_length(const arr_desc *adp,
73 int64_t &offset,
74 int64_t &length);
76 // define if data array described by argument is contiguous one
77 bool is_arr_desc_contiguous(const arr_desc *ap);
79 // allocate element of CeanReadRanges type initialized
80 // to read consequently contiguous ranges described by "ap" argument
81 CeanReadRanges * init_read_ranges_arr_desc(const arr_desc *ap);
83 // check if ranges described by 1 argument could be transfered into ranges
84 // described by 2-nd one
85 bool cean_ranges_match(
86 CeanReadRanges * read_rng1,
87 CeanReadRanges * read_rng2
90 // first argument - returned value by call to init_read_ranges_arr_desc.
91 // returns true if offset and length of next range is set successfuly.
92 // returns false if the ranges is over.
93 bool get_next_range(
94 CeanReadRanges * read_rng,
95 int64_t *offset
98 // returns number of transfered bytes
99 int64_t cean_get_transf_size(CeanReadRanges * read_rng);
101 #if OFFLOAD_DEBUG > 0
102 // prints array descriptor contents to stderr
103 void __arr_desc_dump(
104 const char *spaces,
105 const char *name,
106 const arr_desc *adp,
107 bool dereference);
108 #else
109 #define __arr_desc_dump(
110 spaces,
111 name,
112 adp,
113 dereference)
114 #endif // OFFLOAD_DEBUG
116 #endif // CEAN_UTIL_H_INCLUDED