15bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond/*
25bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* Copyright (C) 2016 The Android Open Source Project
35bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*
45bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* Licensed under the Apache License, Version 2.0 (the "License");
55bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* you may not use this file except in compliance with the License.
65bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* You may obtain a copy of the License at
75bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*
85bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*      http://www.apache.org/licenses/LICENSE-2.0
95bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*
105bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* Unless required by applicable law or agreed to in writing, software
115bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* distributed under the License is distributed on an "AS IS" BASIS,
125bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* See the License for the specific language governing permissions and
145bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* limitations under the License.
155bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*/
165bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond
17dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo#include <memory>
18dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
19dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo#include <jni.h>
20dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo#include <RenderScript.h>
21dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
22dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo#include "ScriptC_allocs.h"
23dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
24dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<RS> mRS;
25dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
26dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mBoolAllocation;  // boolean
27dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
28dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mCharAllocation;  // char
29dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mChar2Allocation;   // char2
30dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mChar3Allocation;   // char3
31dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mChar4Allocation;   // char4
32dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
33dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUCharAllocation;   // uchar
34dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUChar2Allocation;  // uchar2
35dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUChar3Allocation;  // uchar3
36dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUChar4Allocation;  // uchar4
37dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
38dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mShortAllocation;   // short
39dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mShort2Allocation;  // short2
40dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mShort3Allocation;  // short3
41dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mShort4Allocation;  // short4
42dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
43dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUShortAllocation;  // ushort
44dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUShort2Allocation; // ushort2
45dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUShort3Allocation; // ushort3
46dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUShort4Allocation; // ushort4
47dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
48dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mIntAllocation;   // int
49dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mInt2Allocation;  // int2
50dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mInt3Allocation;  // int3
51dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mInt4Allocation;  // int4
52dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
53dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUIntAllocation;  // uint
54dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUInt2Allocation;   // uint2
55dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUInt3Allocation;   // uint3
56dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mUInt4Allocation;   // uint4
57dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
58dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mLongAllocation;  // long
59dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mLong2Allocation;   // long2
60dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mLong3Allocation;   // long3
61dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mLong4Allocation;   // long4
62dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
63dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mULongAllocation;   // ulong
64dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mULong2Allocation;  // ulong2
65dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mULong3Allocation;  // ulong3
66dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mULong4Allocation;  // ulong4
67dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
68dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mHalfAllocation;  // half
69dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mHalf2Allocation;   // half2
70dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mHalf3Allocation;   // half3
71dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mHalf4Allocation;   // half4
72dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
73dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mFloatAllocation;   // float
74dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mFloat2Allocation;  // float2
75dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mFloat3Allocation;  // float3
76dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mFloat4Allocation;  // float4
77dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
78dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mDoubleAllocation;  // double
79dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mDouble2Allocation; // double2
80dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mDouble3Allocation; // double3
81dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leosp<Allocation> mDouble4Allocation; // double4
82dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
83dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leoconst int mAllocSize = 24; // Needs to be < CHAR_MAX and divisible by 4.
84dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leoconst int mBitmapSize = 64;
85dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
86dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leovoid createSignedAllocations() {
87dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeI8Builder(mRS, Element::I8(mRS));
88dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI8Builder.setX(1); // One element here to test 16 byte memory alignment
89dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI8Builder.setY(3);
90dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI8Builder.setZ(8);
91dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
92dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mCharAllocation = Allocation::createTyped(mRS, typeI8Builder.create());
93dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mChar2Allocation = Allocation::createSized(mRS, Element::I8_2(mRS), mAllocSize / 2);
94dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mChar3Allocation = Allocation::createSized(mRS, Element::I8_3(mRS), mAllocSize / 4);
95dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mChar4Allocation = Allocation::createSized(mRS, Element::I8_4(mRS), mAllocSize / 4);
96dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
97dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeI16_2Builder(mRS, Element::I16_2(mRS));
98dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI16_2Builder.setX(6);
99dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI16_2Builder.setY(1);
100dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI16_2Builder.setZ(2);
101dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
102dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShortAllocation = Allocation::createSized(mRS, Element::I16(mRS), mAllocSize);
103dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShort2Allocation = Allocation::createTyped(mRS, typeI16_2Builder.create());
104dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShort3Allocation = Allocation::createSized(mRS, Element::I16_3(mRS), mAllocSize / 4);
105dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShort4Allocation = Allocation::createSized(mRS, Element::I16_4(mRS), mAllocSize / 4);
106dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
107dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeI32_3Builder(mRS, Element::I32_3(mRS));
108dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI32_3Builder.setX(3);
109dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI32_3Builder.setY(2);
110dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
111dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mIntAllocation = Allocation::createSized(mRS, Element::I32(mRS), mAllocSize);
112dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInt2Allocation = Allocation::createSized(mRS, Element::I32_2(mRS), mAllocSize / 2);
113dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInt3Allocation = Allocation::createTyped(mRS, typeI32_3Builder.create());
114dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInt4Allocation = Allocation::createSized(mRS, Element::I32_4(mRS), mAllocSize / 4);
115dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
116dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeI64_4Builder(mRS, Element::I64_4(mRS));
117dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI64_4Builder.setX(1);
118dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeI64_4Builder.setY(6);
119dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
120dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLongAllocation = Allocation::createSized(mRS, Element::I64(mRS), mAllocSize);
121dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLong2Allocation = Allocation::createSized(mRS, Element::I64_2(mRS), mAllocSize / 2);
122dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLong3Allocation = Allocation::createSized(mRS, Element::I64_3(mRS), mAllocSize / 4);
123dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLong4Allocation = Allocation::createTyped(mRS, typeI64_4Builder.create());
124dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
125dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mBoolAllocation = Allocation::createSized(mRS, Element::BOOLEAN(mRS), mAllocSize);
126dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo}
127dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
128dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leovoid initSignedAllocations() {
129dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    char *buffer_char = new char[mAllocSize];
130dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    short *buffer_short = new short[mAllocSize];
131dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    int *buffer_int = new int[mAllocSize];
132dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    int64_t *buffer_long = new int64_t[mAllocSize];
133dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    char *buffer_bool = new char[mAllocSize];
134dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
135dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    for(int i = 0; i < mAllocSize; ++i) {
136dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_char[i] = (char) i;
137dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_short[i] = (short) i;
138dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_int[i] = (int) i;
139dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_long[i] = (int64_t) i;
140dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_bool[i] =  (char) (0x01 & i);
141dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    }
142dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
143dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mCharAllocation->copy3DRangeFrom(0, 0, 0, 1, 3, 8, buffer_char);
144dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mChar2Allocation->copy1DRangeFrom(0, mAllocSize/2, buffer_char);
145dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mChar3Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_char);
146dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mChar4Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_char);
147dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
148dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_char;
149dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
150dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShortAllocation->copy1DRangeFrom(0, mAllocSize, buffer_short);
151dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShort2Allocation->copy3DRangeFrom(0, 0, 0, 6, 1, 2, buffer_short);
152dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShort3Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_short);
153dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShort4Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_short);
154dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
155dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_short;
156dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
157dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mIntAllocation->copy1DRangeFrom(0, mAllocSize, buffer_int);
158dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInt2Allocation->copy1DRangeFrom(0, mAllocSize/2, buffer_int);
159dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInt3Allocation->copy2DRangeFrom(0, 0, 3, 2, buffer_int);
160dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInt4Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_int);
161dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
162dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_int;
163dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
164dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLongAllocation->copy1DRangeFrom(0, mAllocSize, buffer_long);
165dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLong2Allocation->copy1DRangeFrom(0, mAllocSize/2, buffer_long);
166dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLong3Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_long);
167dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLong4Allocation->copy2DRangeFrom(0, 0, 1, 6, buffer_long);
168dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
169dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_long;
170dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
171dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mBoolAllocation->copy1DRangeFrom(0, mAllocSize, buffer_bool);
172dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
173dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_bool;
174dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo}
175dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
176dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leovoid createUnsignedAllocations() {
177dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeU8_2Builder(mRS, Element::U8_2(mRS));
178dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU8_2Builder.setX(2);
179dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU8_2Builder.setY(6);
180dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
181dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUCharAllocation = Allocation::createSized(mRS, Element::U8(mRS), mAllocSize);
182dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUChar2Allocation = Allocation::createTyped(mRS, typeU8_2Builder.create());
183dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUChar3Allocation = Allocation::createSized(mRS, Element::U8_3(mRS), mAllocSize / 4);
184dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUChar4Allocation = Allocation::createSized(mRS, Element::U8_4(mRS), mAllocSize / 4);
185dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
186dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeU16_3Builder(mRS, Element::U16_3(mRS));
187dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU16_3Builder.setX(1);
188dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU16_3Builder.setY(6);
189dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
190dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShortAllocation = Allocation::createSized(mRS, Element::U16(mRS), mAllocSize);
191dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShort2Allocation = Allocation::createSized(mRS, Element::U16_2(mRS), mAllocSize / 2);
192dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShort3Allocation = Allocation::createTyped(mRS, typeU16_3Builder.create());
193dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShort4Allocation = Allocation::createSized(mRS, Element::U16_4(mRS), mAllocSize / 4);
194dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
195dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeU32_4Builder(mRS, Element::U32_4(mRS));
196dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU32_4Builder.setX(1);
197dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU32_4Builder.setY(1);
198dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU32_4Builder.setZ(6);
199dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
200dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUIntAllocation = Allocation::createSized(mRS, Element::U32(mRS), mAllocSize);
201dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUInt2Allocation = Allocation::createSized(mRS, Element::U32_2(mRS), mAllocSize / 2);
202dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUInt3Allocation = Allocation::createSized(mRS, Element::U32_3(mRS), mAllocSize / 4);
203dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUInt4Allocation = Allocation::createTyped(mRS, typeU32_4Builder.create());
204dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
205dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeU64Builder(mRS, Element::U64(mRS));
206dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU64Builder.setX(4);
207dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU64Builder.setY(3);
208dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeU64Builder.setZ(2);
209dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
210dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULongAllocation = Allocation::createTyped(mRS, typeU64Builder.create());
211dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULong2Allocation = Allocation::createSized(mRS, Element::U64_2(mRS), mAllocSize / 2);
212dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULong3Allocation = Allocation::createSized(mRS, Element::U64_3(mRS), mAllocSize / 4);
213dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULong4Allocation = Allocation::createSized(mRS, Element::U64_4(mRS), mAllocSize / 4);
214dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo}
215dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
216dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leovoid initUnsignedAllocations() {
217dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    char *buffer_char = new char[mAllocSize];
218dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    short *buffer_short = new short[mAllocSize];
219dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    int *buffer_int = new int[mAllocSize];
220dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    uint64_t *buffer_long = new uint64_t[mAllocSize];
221dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
222dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    for(int i = 0; i < mAllocSize; ++i) {
223dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_char[i] = (char) i;
224dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_short[i] = (short) i;
225dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_int[i] = (int) i;
226dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_long[i] = (uint64_t) i;
227dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    }
228dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
229dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUCharAllocation->copy1DRangeFrom(0, mAllocSize, buffer_char);
230dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUChar2Allocation->copy2DRangeFrom(0, 0, 2, 6, buffer_char);
231dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUChar3Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_char);
232dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUChar4Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_char);
233dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
234dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_char;
235dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
236dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShortAllocation->copy1DRangeFrom(0, mAllocSize, buffer_short);
237dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShort2Allocation->copy1DRangeFrom(0, mAllocSize/2, buffer_short);
238dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShort3Allocation->copy2DRangeFrom(0, 0, 1, 6, buffer_short);
239dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShort4Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_short);
240dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
241dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_short;
242dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
243dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUIntAllocation->copy1DRangeFrom(0, mAllocSize, buffer_int);
244dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUInt2Allocation->copy1DRangeFrom(0, mAllocSize/2, buffer_int);
245dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUInt3Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_int);
246dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUInt4Allocation->copy3DRangeFrom(0, 0, 0, 1, 1, 6, buffer_int);
247dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
248dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_int;
249dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
250dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULongAllocation->copy3DRangeFrom(0, 0, 0, 4, 3, 2, buffer_long);
251dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULong2Allocation->copy1DRangeFrom(0, mAllocSize/2, buffer_long);
252dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULong3Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_long);
253dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULong4Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_long);
254dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
255dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_long;
256dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo}
257dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
258dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leovoid createFloatAllocations() {
259dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeF16_3Builder(mRS, Element::F16_3(mRS));
260dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF16_3Builder.setX(1);
261dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF16_3Builder.setY(6);
262dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
263dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mHalfAllocation = Allocation::createSized(mRS, Element::F16(mRS), mAllocSize);
264dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mHalf2Allocation = Allocation::createSized(mRS, Element::F16_2(mRS), mAllocSize / 2);
265dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mHalf3Allocation = Allocation::createTyped(mRS, typeF16_3Builder.create());
266dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mHalf4Allocation = Allocation::createSized(mRS, Element::F16_4(mRS), mAllocSize / 4);
267dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
268dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeF32_4Builder(mRS, Element::F32_4(mRS));
269dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF32_4Builder.setX(3);
270dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF32_4Builder.setY(2);
271dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
272dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mFloatAllocation = Allocation::createSized(mRS, Element::F32(mRS), mAllocSize);
273dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mFloat2Allocation = Allocation::createSized(mRS, Element::F32_2(mRS), mAllocSize / 2);
274dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mFloat3Allocation = Allocation::createSized(mRS, Element::F32_3(mRS), mAllocSize / 4);
275dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mFloat4Allocation = Allocation::createTyped(mRS, typeF32_4Builder.create());
276dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
277dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeF64_2Builder(mRS, Element::F64_2(mRS));
278dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF64_2Builder.setX(4);
279dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF64_2Builder.setY(1);
280dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF64_2Builder.setZ(3);
281dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
282dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mDoubleAllocation = Allocation::createSized(mRS, Element::F64(mRS), mAllocSize);
283dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mDouble2Allocation = Allocation::createTyped(mRS, typeF64_2Builder.create());
284dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
285dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeF64_3Builder(mRS, Element::F64_3(mRS));
286dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF64_3Builder.setX(1);
287dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF64_3Builder.setY(2);
288dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF64_3Builder.setZ(3);
289dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
290dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeF64_4Builder(mRS, Element::F64_4(mRS));
291dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF64_4Builder.setX(1);
292dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF64_4Builder.setY(2);
293dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeF64_4Builder.setZ(3);
294dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
295dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mDouble3Allocation = Allocation::createTyped(mRS, typeF64_3Builder.create());
296dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mDouble4Allocation = Allocation::createTyped(mRS, typeF64_4Builder.create());
297dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo}
298dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
299dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leovoid initFloatAllocations() {
300dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    __fp16 *buffer_half = new __fp16[mAllocSize];
301dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    float *buffer_float = new float[mAllocSize];
302dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    double *buffer_double = new double[mAllocSize];
303dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
304dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    for(int i = 0; i < mAllocSize; ++i) {
305dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_half[i] = (__fp16) 1 / i;
306dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_float[i] = (float) 1 / i;
307dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        buffer_double[i] = (double) 1 / i;
308dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    }
309dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
310dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mHalfAllocation->copy1DRangeFrom(0, mAllocSize, buffer_half);
311dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mHalf2Allocation->copy1DRangeFrom(0, mAllocSize/2, buffer_half);
312dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mHalf3Allocation->copy2DRangeFrom(0, 0, 1, 6, buffer_half);
313dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mHalf4Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_half);
314dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
315dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_half;
316dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
317dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mFloatAllocation->copy1DRangeFrom(0, mAllocSize, buffer_float);
318dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mFloat2Allocation->copy1DRangeFrom(0, mAllocSize/2, buffer_float);
319dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mFloat3Allocation->copy1DRangeFrom(0, mAllocSize/4, buffer_float);
320dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mFloat4Allocation->copy2DRangeFrom(0, 0, 3, 2, buffer_float);
321dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
322dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_float;
323dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
324dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mDoubleAllocation->copy1DRangeFrom(0, mAllocSize, buffer_double);
325dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mDouble2Allocation->copy3DRangeFrom(0, 0, 0, 4, 1, 3, buffer_double);
326dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mDouble3Allocation->copy3DRangeFrom(0, 0, 0, 1, 2, 3, buffer_double);
327dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mDouble4Allocation->copy3DRangeFrom(0, 0, 0, 1, 2, 3, buffer_double);
328dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
329dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] buffer_double;
330dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo}
331dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
332dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leoextern "C" void JNICALL
333dcecc0c8d22e894525e25a122ce25129b51338f2Dean De LeoJava_com_android_rs_jniallocations_MainActivity_nativeRS(
334dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo	JNIEnv * env,
335dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo	jclass,
336dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo	jstring pathObj)
337dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo{
338dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mRS = new RS();
339dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
340dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    const char * path = env->GetStringUTFChars(pathObj, nullptr);
341dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mRS->init(path, RS_INIT_LOW_LATENCY | RS_INIT_WAIT_FOR_ATTACH);
342dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    env->ReleaseStringUTFChars(pathObj, path);
343dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
344dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    sp<ScriptC_allocs> mScript = new ScriptC_allocs(mRS);
345dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
346dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder typeRGBA_888Builder(mRS, Element::RGBA_8888(mRS));
347dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeRGBA_888Builder.setX(mBitmapSize);
348dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    typeRGBA_888Builder.setY(mBitmapSize);
349dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
350dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    sp<Allocation> mInAllocation = Allocation::createTyped(mRS, typeRGBA_888Builder.create());
351dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
352dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    const int image_area = mBitmapSize*mBitmapSize;
353dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    const int image_size = image_area*sizeof(int);
354dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
355dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    char *zero_buffer = new char[image_size];
356dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    memset(zero_buffer, 0, image_size);
357dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInAllocation->copy1DRangeFrom(0, image_area, zero_buffer);
358dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] zero_buffer;
359dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
360dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    sp<Allocation> mOutAllocation = Allocation::createTyped(mRS, typeRGBA_888Builder.create());
361dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    createSignedAllocations();
362dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    initSignedAllocations();
363dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
364dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mRS->finish();
365dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mScript->forEach_swizzle_kernel(mInAllocation, mOutAllocation);
366dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mRS->finish();
367dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
368dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mCharAllocation.clear();
369dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mChar2Allocation.clear();
370dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mChar3Allocation.clear();
371dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mChar4Allocation.clear();
372dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
373dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShort2Allocation.clear();
374dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShort3Allocation.clear();
375dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mShort4Allocation.clear();
376dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
377dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mIntAllocation.clear();
378dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInt2Allocation.clear();
379dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInt3Allocation.clear();
380dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInt4Allocation.clear();
381dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
382dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLongAllocation.clear();
383dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLong2Allocation.clear();
384dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLong3Allocation.clear();
385dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mLong4Allocation.clear();
386dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
387dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mBoolAllocation.clear();
388dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
389dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    createUnsignedAllocations();
390dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    initUnsignedAllocations();
391dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
392dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mInAllocation = mUShortAllocation; // Host side assignment
393dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
394dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mRS->finish();
395dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mScript->forEach_square_kernel(mInAllocation, mUIntAllocation);
396dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mRS->finish();
397dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
398dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUCharAllocation.clear();
399dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUChar2Allocation.clear();
400dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUChar3Allocation.clear();
401dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUChar4Allocation.clear();
402dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
403dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShortAllocation.clear();
404dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShort2Allocation.clear();
405dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShort3Allocation.clear();
406dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUShort4Allocation.clear();
407dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
408dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUInt2Allocation.clear();
409dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUInt3Allocation.clear();
410dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mUInt4Allocation.clear();
411dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
412dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULongAllocation.clear();
413dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULong2Allocation.clear();
414dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULong3Allocation.clear();
415dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mULong4Allocation.clear();
416dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
417dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    createFloatAllocations();
418dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    initFloatAllocations();
419dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
420dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mRS->finish();
421dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mScript->forEach_add_half_kernel(mDouble4Allocation, mDouble3Allocation);
422dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    mRS->finish();
423dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo}
424dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
425