diff options
author | Jason Sams <jsams@google.com> | 2013-01-22 21:30:17 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-01-22 21:30:18 +0000 |
commit | b472aade9e052b92cbd0fb55648d21b282f0ede7 (patch) | |
tree | 2000ad7b175838bbffb2ee76b3b8b2e5dc168a9d /tests/RenderScriptTests | |
parent | 7384db20b82b829d0e52642a58475846a27c0ca4 (diff) | |
parent | 023c260afae65a974158e894a3d376cefbd12f58 (diff) | |
download | frameworks_base-b472aade9e052b92cbd0fb55648d21b282f0ede7.zip frameworks_base-b472aade9e052b92cbd0fb55648d21b282f0ede7.tar.gz frameworks_base-b472aade9e052b92cbd0fb55648d21b282f0ede7.tar.bz2 |
Merge "fast math error testing."
Diffstat (limited to 'tests/RenderScriptTests')
8 files changed, 296 insertions, 4 deletions
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vibrance.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vibrance.rs index 677e857..fae94a1 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vibrance.rs +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vibrance.rs @@ -16,7 +16,6 @@ #pragma version(1) #pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed float vibrance = 0.f; @@ -39,7 +38,7 @@ void vibranceKernel(const uchar4 *in, uchar4 *out) { int g = in->g; int b = in->b; float red = (r-max(g, b))/256.f; - float sx = (float)(Vib/(1+exp(-red*3))); + float sx = (float)(Vib/(1+native_exp(-red*3))); S = sx+1; MS = 1.0f - S; Rt = Rf * MS; diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx.rsh b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx.rsh index 05a5929..5668621 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx.rsh +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx.rsh @@ -50,8 +50,7 @@ uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) { const float2 inCoord = {(float)x, (float)y}; const float2 coord = mad(inCoord, inv_dimensions, neg_center); const float sloped_dist_ratio = fast_length(axis_scale * coord) * sloped_inv_max_dist; - // TODO: add half_exp once implemented - const float lumen = opp_shade + shade * half_recip(1.f + sloped_neg_range * exp(sloped_dist_ratio)); + const float lumen = opp_shade + shade * half_recip(1.f + sloped_neg_range * native_exp(sloped_dist_ratio)); float4 fout; fout.rgb = fin.rgb * lumen; fout.w = fin.w; diff --git a/tests/RenderScriptTests/MathErr/Android.mk b/tests/RenderScriptTests/MathErr/Android.mk new file mode 100644 index 0000000..b3edd02 --- /dev/null +++ b/tests/RenderScriptTests/MathErr/Android.mk @@ -0,0 +1,27 @@ +# +# Copyright (C) 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-java-files-under, src) \ + $(call all-renderscript-files-under, src) + +LOCAL_PACKAGE_NAME := RsMathErr + +include $(BUILD_PACKAGE) diff --git a/tests/RenderScriptTests/MathErr/AndroidManifest.xml b/tests/RenderScriptTests/MathErr/AndroidManifest.xml new file mode 100644 index 0000000..6a3db2c --- /dev/null +++ b/tests/RenderScriptTests/MathErr/AndroidManifest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android.rs.matherr"> + + <uses-sdk android:minSdkVersion="17" /> + <application android:label="RS Math Err"> + <activity android:name="MathErrActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/tests/RenderScriptTests/MathErr/res/layout/main.xml b/tests/RenderScriptTests/MathErr/res/layout/main.xml new file mode 100644 index 0000000..7b2c76a --- /dev/null +++ b/tests/RenderScriptTests/MathErr/res/layout/main.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <ImageView + android:id="@+id/displayin" + android:layout_width="320dip" + android:layout_height="266dip" /> + + <ImageView + android:id="@+id/displayout" + android:layout_width="320dip" + android:layout_height="266dip" /> + +</LinearLayout> diff --git a/tests/RenderScriptTests/MathErr/src/com/example/android/rs/matherr/MathErr.java b/tests/RenderScriptTests/MathErr/src/com/example/android/rs/matherr/MathErr.java new file mode 100644 index 0000000..4561267 --- /dev/null +++ b/tests/RenderScriptTests/MathErr/src/com/example/android/rs/matherr/MathErr.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.rs.matherr; + +import android.content.res.Resources; +import android.renderscript.*; +import java.lang.Float; +import java.lang.Math; + +public class MathErr { + private RenderScript mRS; + private Allocation mAllocationSrc; + private Allocation mAllocationRes; + private ScriptC_math_err mScript; + private java.util.Random mRand = new java.util.Random(); + + private final int BUF_SIZE = 4096; + float mSrc[] = new float[BUF_SIZE]; + float mRef[] = new float[BUF_SIZE]; + float mRes[] = new float[BUF_SIZE]; + + MathErr(RenderScript rs) { + mRS = rs; + mScript = new ScriptC_math_err(mRS); + + mAllocationSrc = Allocation.createSized(rs, Element.F32(rs), BUF_SIZE); + mAllocationRes = Allocation.createSized(rs, Element.F32(rs), BUF_SIZE); + + testExp2(); + testLog2(); + } + + void buildRand() { + for (int i=0; i < BUF_SIZE; i++) { + mSrc[i] = (((float)i) / 9) - 200; + //mSrc[i] = Float.intBitsToFloat(mRand.nextInt()); + } + mAllocationSrc.copyFrom(mSrc); + } + + void logErr() { + mAllocationRes.copyTo(mRes); + for (int i=0; i < BUF_SIZE; i++) { + int err = Float.floatToRawIntBits(mRef[i]) - Float.floatToRawIntBits(mRes[i]); + err = Math.abs(err); + if (err > 8096) { + android.util.Log.v("err", "error " + err + " src " + mSrc[i] + " ref " + mRef[i] + " res " + mRes[i]); + } + } + } + + void testExp2() { + android.util.Log.v("err", "testing exp2"); + buildRand(); + mScript.forEach_testExp2(mAllocationSrc, mAllocationRes); + for (int i=0; i < BUF_SIZE; i++) { + mRef[i] = (float)Math.pow(2.f, mSrc[i]); + } + logErr(); + } + + void testLog2() { + android.util.Log.v("err", "testing log2"); + buildRand(); + mScript.forEach_testLog2(mAllocationSrc, mAllocationRes); + for (int i=0; i < BUF_SIZE; i++) { + mRef[i] = (float)Math.log(mSrc[i]) * 1.442695041f; + } + logErr(); + } + +} diff --git a/tests/RenderScriptTests/MathErr/src/com/example/android/rs/matherr/MathErrActivity.java b/tests/RenderScriptTests/MathErr/src/com/example/android/rs/matherr/MathErrActivity.java new file mode 100644 index 0000000..74d7b71 --- /dev/null +++ b/tests/RenderScriptTests/MathErr/src/com/example/android/rs/matherr/MathErrActivity.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.rs.matherr; + +import android.app.Activity; +import android.os.Bundle; +import android.renderscript.RenderScript; +import android.renderscript.Allocation; +import android.util.Log; + +public class MathErrActivity extends Activity { + private MathErr mME; + private RenderScript mRS; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + mRS = RenderScript.create(this); + mME = new MathErr(mRS); + } +} diff --git a/tests/RenderScriptTests/MathErr/src/com/example/android/rs/matherr/math_err.rs b/tests/RenderScriptTests/MathErr/src/com/example/android/rs/matherr/math_err.rs new file mode 100644 index 0000000..a26770b --- /dev/null +++ b/tests/RenderScriptTests/MathErr/src/com/example/android/rs/matherr/math_err.rs @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma version(1) +#pragma rs java_package_name(com.example.android.rs.matherr) + +typedef union +{ + float fv; + int32_t iv; +} ieee_float_shape_type; + +/* Get a 32 bit int from a float. */ + +#define GET_FLOAT_WORD(i,d) \ +do { \ + ieee_float_shape_type gf_u; \ + gf_u.fv = (d); \ + (i) = gf_u.iv; \ +} while (0) + +/* Set a float from a 32 bit int. */ + +#define SET_FLOAT_WORD(d,i) \ +do { \ + ieee_float_shape_type sf_u; \ + sf_u.iv = (i); \ + (d) = sf_u.fv; \ +} while (0) + + +static float fast_log2(float v) { + int32_t ibits; + GET_FLOAT_WORD(ibits, v); + + int32_t e = (ibits >> 23) & 0xff; + + ibits &= 0x7fffff; + ibits |= 127 << 23; + + float ir; + SET_FLOAT_WORD(ir, ibits); + + ir -= 1.5f; + float ir2 = ir*ir; + float adj2 = 0.405465108f + // -0.00009f + + (0.666666667f * ir) - + (0.222222222f * ir2) + + (0.098765432f * ir*ir2) - + (0.049382716f * ir2*ir2) + + (0.026337449f * ir*ir2*ir2) - + (0.014631916f * ir2*ir2*ir2); + adj2 *= (1.f / 0.693147181f); + + return (float)(e - 127) + adj2; +} + +void testExp2(const float *in, float *out) { + float i = *in; + if (i > (-125.f) && i < 125.f) { + *out = native_exp2(i); + } else { + *out = exp2(i); + } + *out = native_exp2(i); +} + +void testLog2(const float *in, float *out) { + *out = fast_log2(*in); +} + |