public void test_AllocationPadded_copy1DRangeToUnchecked_Byte3() { Random random = new Random(0x172d8ab9); int width = random.nextInt(512); int arr_len = width * 3; byte[] inArray = new byte[arr_len]; byte[] outArray = new byte[arr_len]; random.nextBytes(inArray); Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); typeBuilder.setX(width); Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); alloc.setAutoPadding(true); int offset = random.nextInt(width); int count = width - offset; alloc.copy1DRangeFrom(offset, count, inArray); alloc.copy1DRangeToUnchecked(offset, count, outArray); boolean result = true; for (int i = 0; i < count * 3; i++) { if (inArray[i] != outArray[i]) { result = false; break; } } for (int i = count * 3; i < arr_len; i++) { if (outArray[i] != 0) { result = false; break; } } assertTrue( "test_copy1DRangeToUnchecked_Padded_Byte Failed, output array does not match input", result); }
private void float4input(long seed, int testId) { Allocation mAllocationIn = Allocation.createSized(mRS, Element.F32_4(mRS), INPUTSIZE); Allocation mAllocationOut = Allocation.createSized(mRS, Element.U8_4(mRS), INPUTSIZE); float[] inArray = new float[INPUTSIZE * 4]; byte[] outArray = new byte[INPUTSIZE * 4]; byte[] refArray = new byte[INPUTSIZE * 4]; RSUtils.genRandom(seed, 1, 0, inArray); mAllocationIn.copy1DRangeFrom(0, INPUTSIZE, inArray); try { RSUtils.forEach(this, testId, mAllocationIn, mAllocationOut); } catch (RSRuntimeException e) { } mAllocationOut.copyTo(outArray); for (int i = 0; i < outArray.length; i += 4) { int offset = i; Float4 inValues = new Float4( inArray[offset], inArray[offset + 1], inArray[offset + 2], inArray[offset + 3]); byte[] cValue = rs_PackColorTo8888(inValues); refArray[i] = cValue[0]; refArray[i + 1] = cValue[1]; refArray[i + 2] = cValue[2]; refArray[i + 3] = cValue[3]; for (int j = 0; j < 4; j++) { assertEquals(refArray[i + j] & 0xff, outArray[i + j] & 0xff); } } }
protected void createWalk(int vsize) { // We do a random copy order to attempt to get multiple threads // reading and writing the same cache line // We could do this as a simple walk but that would likely miss // some caching issues. final int tw = gCount / vsize; int tmp[] = new int[tw]; boolean b[] = new boolean[tw]; int toCopy = tw; int i = 0; while (toCopy > 0) { int x = random.nextInt(tw); while ((x < tw) && b[x]) { x++; if (x >= tw) { x = 0; } } b[x] = true; toCopy--; // android.util.Log.v("rs", "walk " + i + ", " + x); tmp[i++] = x; } walkAlloc = Allocation.createSized(mRS, Element.I32(mRS), tw); walkAlloc.copy1DRangeFrom(0, tw, tmp); }