Clean up some minor white space issues in trans-decl.c and trans-expr.c
[official-gcc.git] / liboffloadmic / runtime / cean_util.h
blob8b7c437673907f11a943ca9bae0bda69e9a0178b
1 /*
2 Copyright (c) 2014-2015 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>
35 #include "offload_util.h"
37 // CEAN expression representation
38 struct Dim_Desc {
39 int64_t size; // Length of data type
40 int64_t lindex; // Lower index
41 int64_t lower; // Lower section bound
42 int64_t upper; // Upper section bound
43 int64_t stride; // Stride
46 struct Arr_Desc {
47 int64_t base; // Base address
48 int64_t rank; // Rank of array
49 Dim_Desc dim[1];
52 struct CeanReadDim {
53 int64_t count; // The number of elements in this dimension
54 int64_t size; // The number of bytes between successive
55 // elements in this dimension.
58 struct CeanReadRanges {
59 Arr_Desc* arr_desc;
60 void * ptr;
61 int64_t current_number; // the number of ranges read
62 int64_t range_max_number; // number of contiguous ranges
63 int64_t range_size; // size of max contiguous range
64 int last_noncont_ind; // size of Dim array
65 int64_t init_offset; // offset of 1-st element from array left bound
66 CeanReadDim Dim[1];
69 // array descriptor length
70 #define __arr_desc_length(rank) \
71 (sizeof(int64_t) + sizeof(Dim_Desc) * (rank))
73 // returns offset and length of the data to be transferred
74 DLL_LOCAL void __arr_data_offset_and_length(const Arr_Desc *adp,
75 int64_t &offset,
76 int64_t &length);
78 // define if data array described by argument is contiguous one
79 DLL_LOCAL bool is_arr_desc_contiguous(const Arr_Desc *ap);
81 // allocate element of CeanReadRanges type initialized
82 // to read consequently contiguous ranges described by "ap" argument
83 DLL_LOCAL CeanReadRanges * init_read_ranges_arr_desc(const Arr_Desc *ap);
85 // check if ranges described by 1 argument could be transferred into ranges
86 // described by 2-nd one
87 DLL_LOCAL bool cean_ranges_match(
88 CeanReadRanges * read_rng1,
89 CeanReadRanges * read_rng2
92 // first argument - returned value by call to init_read_ranges_arr_desc.
93 // returns true if offset and length of next range is set successfuly.
94 // returns false if the ranges is over.
95 DLL_LOCAL bool get_next_range(
96 CeanReadRanges * read_rng,
97 int64_t *offset
100 // returns number of transferred bytes
101 DLL_LOCAL int64_t cean_get_transf_size(CeanReadRanges * read_rng);
103 #if OFFLOAD_DEBUG > 0
104 // prints array descriptor contents to stderr
105 DLL_LOCAL void __arr_desc_dump(
106 const char *spaces,
107 const char *name,
108 const Arr_Desc *adp,
109 bool dereference,
110 bool print_values);
111 #define ARRAY_DESC_DUMP(spaces, name, adp, dereference, print_values) \
112 if (console_enabled >= 2) \
113 __arr_desc_dump(spaces, name, adp, dereference, print_values);
114 #else
115 #define ARRAY_DESC_DUMP(spaces, name, adp, dereference, print_values)
116 #endif // OFFLOAD_DEBUG
118 #endif // CEAN_UTIL_H_INCLUDED