I need to perform matrix operations in Android, so I searched about the RenderScript, and I got useful information here
I tried the program in the answer above like this:
private void compute(){
mRs = RenderScript.create(this);
Type.Builder builder = new Type.Builder(mRs, Element.U8(mRs));
Type a_type = builder.setX(3).setY(2).create();
Type b_type = builder.setX(3).setY(2).create();
Type c_type = builder.setX(2).setY(2).create();
Allocation A = Allocation.createTyped(mRs, a_type);
Allocation B = Allocation.createTyped(mRs, b_type);
Allocation C = Allocation.createTyped(mRs, c_type);
A.copyFrom(new byte[]{1, 2, 3, 1, 2, 3});
B.copyFrom(new byte[]{1, 1, 1, 0, 1, 0});
ScriptIntrinsicBLAS BLAS = ScriptIntrinsicBLAS.create(mRs);
BLAS.BNNM(A, 0, B, 0, C, 0, 1);
byte[] result = new byte[]{1,2,3,4};
C.copyTo(result);
for(int i = 0; i < result.length; ++i){
Log.i(TAG, i + " " + result[i]);
}
}
My gradle file is like this following:
targetSdkVersion 25
renderscriptTargetApi 25
renderscriptSupportModeEnabled true
renderscriptSupportModeBlasEnabled true
But I got the wrong results that all items in the matrix C is zero:
08-25 16:31:05.384 30771-30771/cn.jy.testsiblas I/tag: 0 0
08-25 16:31:05.384 30771-30771/cn.jy.testsiblas I/tag: 1 0
08-25 16:31:05.384 30771-30771/cn.jy.testsiblas I/tag: 2 0
08-25 16:31:05.384 30771-30771/cn.jy.testsiblas I/tag: 3 0
Someone knows how to solve this?
Besides, I have just found there seems to be limitation in the dimensions of matrix that can be handled with ScriptIntrinsicBLAS? here is a question about this Anyone know about this limitation? If limitation is real, I'm afraid I have to find out another way to handle matrix operation on Android.