Loading tests/RenderScriptTests/LargeMatrix/Android.mk 0 → 100644 +27 −0 Original line number Diff line number Diff line # # Copyright (C) 2012 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 := LargeMatrix include $(BUILD_PACKAGE) tests/RenderScriptTests/LargeMatrix/AndroidManifest.xml 0 → 100644 +15 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.rs.matrix"> <uses-sdk android:minSdkVersion="16" /> <application android:label="Large Matrix" android:hardwareAccelerated="true"> <activity android:name="MatrixActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> tests/RenderScriptTests/LargeMatrix/src/com/android/rs/matrix/MatrixActivity.java 0 → 100644 +77 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 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.android.rs.matrix; import java.lang.Math; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.os.Bundle; import android.renderscript.*; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.widget.ImageView; import android.widget.SeekBar; import android.widget.TextView; public class MatrixActivity extends Activity { private RenderScript mRS; private ScriptC_large_matrix mScript; private Allocation mVectorIn; private Allocation mVectorOut; private Allocation mMatrix; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mRS = RenderScript.create(this); Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS)); tb.setX(2000); tb.setY(500); Type t = tb.create(); mMatrix = Allocation.createTyped(mRS, t); mVectorIn = Allocation.createSized(mRS, Element.F32_4(mRS), 500); mVectorOut = Allocation.createSized(mRS, Element.F32_4(mRS), 500); mScript = new ScriptC_large_matrix(mRS, getResources(), R.raw.large_matrix); mScript.set_gMatrix(mMatrix); mRS.finish(); long dt = java.lang.System.currentTimeMillis(); for (int i=0; i<100; i++) { mScript.forEach_multiply_row(mVectorIn, mVectorOut); } mRS.finish(); dt = (java.lang.System.currentTimeMillis() - dt); Log.v("rs", "LargeMatrix mult time ms " + dt); float gflop = 2000.f * 2000.f * 2.f / dt / 1000000.f; gflop *= 100; Log.v("rs", "LargeMatrix gflop " + gflop); } } tests/RenderScriptTests/LargeMatrix/src/com/android/rs/matrix/large_matrix.rs 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 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.android.rs.matrix) rs_allocation gMatrix; void multiply_row(const float4 *in, float4 *out, uint32_t x) { uint32_t dimX = rsAllocationGetDimX(gMatrix); const float4 *m = (const float4 *)rsGetElementAt(gMatrix, 0, x); float4 sum = m[0] * in[0]; for(uint32_t ct=1; ct < dimX; ct++) { sum += m[ct] * in[0]; } *out = sum; } Loading
tests/RenderScriptTests/LargeMatrix/Android.mk 0 → 100644 +27 −0 Original line number Diff line number Diff line # # Copyright (C) 2012 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 := LargeMatrix include $(BUILD_PACKAGE)
tests/RenderScriptTests/LargeMatrix/AndroidManifest.xml 0 → 100644 +15 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.rs.matrix"> <uses-sdk android:minSdkVersion="16" /> <application android:label="Large Matrix" android:hardwareAccelerated="true"> <activity android:name="MatrixActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
tests/RenderScriptTests/LargeMatrix/src/com/android/rs/matrix/MatrixActivity.java 0 → 100644 +77 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 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.android.rs.matrix; import java.lang.Math; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.os.Bundle; import android.renderscript.*; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.widget.ImageView; import android.widget.SeekBar; import android.widget.TextView; public class MatrixActivity extends Activity { private RenderScript mRS; private ScriptC_large_matrix mScript; private Allocation mVectorIn; private Allocation mVectorOut; private Allocation mMatrix; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mRS = RenderScript.create(this); Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS)); tb.setX(2000); tb.setY(500); Type t = tb.create(); mMatrix = Allocation.createTyped(mRS, t); mVectorIn = Allocation.createSized(mRS, Element.F32_4(mRS), 500); mVectorOut = Allocation.createSized(mRS, Element.F32_4(mRS), 500); mScript = new ScriptC_large_matrix(mRS, getResources(), R.raw.large_matrix); mScript.set_gMatrix(mMatrix); mRS.finish(); long dt = java.lang.System.currentTimeMillis(); for (int i=0; i<100; i++) { mScript.forEach_multiply_row(mVectorIn, mVectorOut); } mRS.finish(); dt = (java.lang.System.currentTimeMillis() - dt); Log.v("rs", "LargeMatrix mult time ms " + dt); float gflop = 2000.f * 2000.f * 2.f / dt / 1000000.f; gflop *= 100; Log.v("rs", "LargeMatrix gflop " + gflop); } }
tests/RenderScriptTests/LargeMatrix/src/com/android/rs/matrix/large_matrix.rs 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 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.android.rs.matrix) rs_allocation gMatrix; void multiply_row(const float4 *in, float4 *out, uint32_t x) { uint32_t dimX = rsAllocationGetDimX(gMatrix); const float4 *m = (const float4 *)rsGetElementAt(gMatrix, 0, x); float4 sum = m[0] * in[0]; for(uint32_t ct=1; ct < dimX; ct++) { sum += m[ct] * in[0]; } *out = sum; }