2 Copyright (c) 2014-2016 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
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 #include "offload_common.h"
33 bool __dv_is_contiguous(const ArrDesc
*dvp
)
35 if (dvp
->Flags
& ArrDescFlagsContiguous
) {
40 if (dvp
->Dim
[0].Mult
!= dvp
->Len
) {
43 for (int i
= 1; i
< dvp
->Rank
; i
++) {
44 if (dvp
->Dim
[i
].Mult
!=
45 dvp
->Dim
[i
-1].Extent
* dvp
->Dim
[i
-1].Mult
) {
53 bool __dv_is_allocated(const ArrDesc
*dvp
)
55 return (dvp
->Flags
& ArrDescFlagsDefined
);
58 uint64_t __dv_data_length(const ArrDesc
*dvp
)
68 for (int i
= 0; i
< dvp
->Rank
; ++i
) {
69 size
+= (dvp
->Dim
[i
].Extent
-1) * dvp
->Dim
[i
].Mult
;
74 uint64_t __dv_data_length(const ArrDesc
*dvp
, int64_t count
)
80 return count
* dvp
->Dim
[0].Mult
;
83 // Create CeanReadRanges data for reading contiguous ranges of
84 // noncontiguous array defined by the argument
85 CeanReadRanges
* init_read_ranges_dv(const ArrDesc
*dvp
)
90 CeanReadRanges
*res
= NULL
;
95 if (dvp
->Dim
[0].Mult
== len
) {
96 for (i
= 1; i
< rank
; i
++) {
97 len
*= dvp
->Dim
[i
-1].Extent
;
98 if (dvp
->Dim
[i
].Mult
!= len
) {
103 res
= (CeanReadRanges
*)malloc(
104 sizeof(CeanReadRanges
) + (rank
- i
) * sizeof(CeanReadDim
));
106 LIBOFFLOAD_ERROR(c_malloc
);
107 res
-> last_noncont_ind
= rank
- i
- 1;
109 for (; i
< rank
; i
++) {
110 res
->Dim
[rank
- i
- 1].count
= count
;
111 res
->Dim
[rank
- i
- 1].size
= dvp
->Dim
[i
].Mult
;
112 count
*= dvp
->Dim
[i
].Extent
;
114 res
-> range_max_number
= count
;
115 res
-> range_size
= len
;
116 res
-> ptr
= (void*)dvp
->Base
;
117 res
-> current_number
= 0;
118 res
-> init_offset
= 0;
123 #if OFFLOAD_DEBUG > 0
124 void __dv_desc_dump(const char *name
, const ArrDesc
*dvp
)
126 OFFLOAD_TRACE(3, "%s DV %p\n", name
, dvp
);
130 " dv->Base = 0x%lx\n"
132 " dv->Offset = 0x%lx\n"
133 " dv->Flags = 0x%lx\n"
134 " dv->Rank = 0x%lx\n"
135 " dv->Resrvd = 0x%lx\n",
143 for (int i
= 0 ; i
< dvp
->Rank
; i
++) {
145 " (%d) Extent=%ld, Multiplier=%ld, LowerBound=%ld\n",
149 dvp
->Dim
[i
].LowerBound
);
153 #endif // OFFLOAD_DEBUG > 0