本文整理汇总了Java中android.renderscript.Allocation.createSized方法的典型用法代码示例。如果您正苦于以下问题:Java Allocation.createSized方法的具体用法?Java Allocation.createSized怎么用?Java Allocation.createSized使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.renderscript.Allocation
的用法示例。
在下文中一共展示了Allocation.createSized方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMatch
import android.renderscript.Allocation; //导入方法依赖的package包/类
public Rect findMatch(ScriptC_find_region findRegion, RenderScript mRs, Bitmap image) {
long time = System.nanoTime();
Allocation border_coords;
border_coords = allocFloat2(mPointsXY, mRs);
Allocation aImage = Allocation.createFromBitmap(mRs, image);
Allocation ret = Allocation.createSized(mRs, Element.I32_2(mRs), 1);
findRegion.invoke_findRegion(border_coords, aImage, image.getWidth(), image.getHeight(), ret);
int[] mina = new int[2];
ret.copyTo(mina);
mCutOffsetX = mina[0];
mCutOffsetY = mina[1];
Log.v(TAG, "New best location = " + mCutOffsetX + ", " + mCutOffsetY);
Log.v(TAG, "Time to find replacement= " + (System.nanoTime() - time) / 1E6f + "ms");
return mRoiBounds;
}
示例2: allocIntermediateVariables
import android.renderscript.Allocation; //导入方法依赖的package包/类
private void allocIntermediateVariables() {
Allocation cAlloc = Allocation.createSized(mRs, Element.F32(mRs), hidden_units);
scriptC_main.bind_c(cAlloc);
Allocation hAlloc = Allocation.createSized(mRs, Element.F32(mRs), hidden_units);
scriptC_main.bind_h(hAlloc);
Allocation inputConcatAlloc = Allocation.createSized(mRs, Element.F32(mRs),
hidden_units * 2);
scriptC_main.bind_input_concat(inputConcatAlloc);
Allocation linearResultAlloc = Allocation.createSized(mRs, Element.F32(mRs),
hidden_units * 4);
scriptC_main.bind_linear_result(linearResultAlloc);
}
示例3: run
import android.renderscript.Allocation; //导入方法依赖的package包/类
public void run() {
RenderScript mRS = RenderScript.create(mCtx);
int numElements = inputData.length/2;
Allocation mInAllocation = Allocation.createSized(mRS, Element.F32_2(mRS), numElements);
mInAllocation.copyFrom(inputData);
Allocation mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
ScriptC_fft mScript = new ScriptC_fft(mRS, mRes, R.raw.fft);
mScript.invoke_runRestricted(mScript, mInAllocation, mOutAllocation);
mOutAllocation.copyTo(outputData);
mInAllocation.copyTo(inputData);
System.out.println("Debug: inBuff " + Arrays.toString(inputData));
System.out.println("Debug: outBuff " + Arrays.toString(outputData));
}
示例4: run
import android.renderscript.Allocation; //导入方法依赖的package包/类
public void run() {
RenderScript mRS = RenderScript.create(mCtx);
int numElements = inputData.length/2;
Allocation mInAllocation = Allocation.createSized(mRS, Element.F32_2(mRS), numElements);
mInAllocation.copyFrom(inputData);
Allocation mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
ScriptC_ifft mScript = new ScriptC_ifft(mRS, mRes, R.raw.ifft);
mScript.invoke_runRestricted(mScript, mInAllocation, mOutAllocation, numElements);
mOutAllocation.copyTo(outputData);
mInAllocation.copyTo(inputData);
System.out.println("Debug: inBuff " + Arrays.toString(inputData));
System.out.println("Debug: outBuff " + Arrays.toString(outputData));
}
示例5: initializeParamsAllocation
import android.renderscript.Allocation; //导入方法依赖的package包/类
private void initializeParamsAllocation() {
Type wInType = Type.createXY(mRs, Element.F32(mRs), hidden_units, inDim);
Allocation wInAlloc = Allocation.createTyped(mRs, wInType);
wInAlloc.copyFrom(convertedWIn);
scriptC_main.set_w_in(wInAlloc);
Allocation bInAlloc = Allocation.createSized(mRs, Element.F32(mRs), hidden_units);
bInAlloc.copyFrom(b_in);
scriptC_main.set_b_in(bInAlloc);
Type wOutType = Type.createXY(mRs, Element.F32(mRs), outDim, hidden_units);
Allocation wOutAlloc = Allocation.createTyped(mRs, wOutType);
wOutAlloc.copyFrom(convertedWOut);
scriptC_main.set_w_out(wOutAlloc);
Allocation bOutAlloc = Allocation.createSized(mRs, Element.F32(mRs), outDim);
bOutAlloc.copyFrom(b_out);
scriptC_main.set_b_out(bOutAlloc);
Type weightType = Type.createXYZ(mRs, Element.F32(mRs),
hidden_units * 4, hidden_units * 2, layerSize);
Allocation weightAlloc = Allocation.createTyped(mRs, weightType);
weightAlloc.copyFrom(convertedWeights);
scriptC_main.set_weights(weightAlloc);
Type biasType = Type.createXY(mRs, Element.F32(mRs), hidden_units * 4, layerSize);
Allocation biasAlloc = Allocation.createTyped(mRs, biasType);
biasAlloc.copyFrom(convertedBiases);
scriptC_main.set_biases(biasAlloc);
}
示例6: predictOnGpu
import android.renderscript.Allocation; //导入方法依赖的package包/类
private int predictOnGpu(float[][] x) {
if (mRs == null) {
return -1;
}
int timeSteps = x.length;
float[] convertedX = alter2Dto1D(x);
scriptC_main.set_time_steps(timeSteps);
scriptC_main.set_in_dim(inDim);
scriptC_main.set_hidden_unites(hidden_units);
scriptC_main.set_layer_size(layerSize);
// initialize input raw data allocation
Type inRawType = Type.createXY(mRs, Element.F32(mRs), inDim, timeSteps);
Allocation inputRawAlloc = Allocation.createTyped(mRs, inRawType);
inputRawAlloc.copyFrom(convertedX);
scriptC_main.set_input_raw(inputRawAlloc);
// initialize activated input data allocation
Type cellDataType = Type.createXY(mRs, Element.F32(mRs), hidden_units, timeSteps);
Allocation inputsAlloc = Allocation.createTyped(mRs, cellDataType);
scriptC_main.set_inputs(inputsAlloc);
// initialize model parameters(weights and biases) allocation
initializeParamsAllocation();
allocIntermediateVariables();
// initialize label probability output allocation
Allocation labelProbAlloc = Allocation.createSized(mRs, Element.F32(mRs), outDim);
scriptC_main.bind_label_prob(labelProbAlloc);
scriptC_main.set_out_dim(outDim);
// begin model forward pass computation
long start = System.currentTimeMillis();
scriptC_main.invoke_all_in_one();
//// scriptC_main.forEach_input_transform(inputsAlloc);
// scriptC_main.invoke_input_transform_func();
// for (int i = 0; i < layerSize; i++) {
//// scriptC_main.forEach_set_zeros(cAlloc);
//// scriptC_main.forEach_set_zeros(hAlloc);
// scriptC_main.invoke_set_ch_zeros();
// scriptC_main.set_current_layer(i);
// for (int j = 0; j < timeSteps; j++) {
// scriptC_main.set_current_step(j);
// scriptC_main.invoke_calc_cell_one_step();
//// scriptC_main.invoke_concat_in_h();
//
//// scriptC_main.forEach_linear_map(linearResultAlloc);
//// scriptC_main.invoke_linear_map_func();
//
//// scriptC_main.forEach_pointwise_ch(cAlloc);// or pass hAlloc
//// scriptC_main.invoke_pointwise_ch_func();
//
//// scriptC_main.forEach_update_input(hAlloc);
//// scriptC_main.invoke_update_input_func();
// }
// }
//// scriptC_main.forEach_output_transform(labelProbAlloc);
// scriptC_main.invoke_output_transform_func();
mRs.finish();
long end = System.currentTimeMillis();
// copy result back
float[] labelProb = new float[outDim];
labelProbAlloc.copyTo(labelProb);
Logger.i("invoke time: %s", (end - start));
return DataUtil.argmax(labelProb) + 1;
}
示例7: run
import android.renderscript.Allocation; //导入方法依赖的package包/类
public void run() {
RenderScript mRS = RenderScript.create(mCtx);
Allocation mInAllocation = Allocation.createSized(mRS, Element.F32(mRS), inputData.length);
mInAllocation.copyFrom(inputData);
Allocation mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
//ScriptC_hamming mScript = new ScriptC_hamming(mRS, mRes, R.raw.hamming);
//mScript.set_invN(1.0f / (inputData.length - 1));
//mScript.forEach_root(mInAllocation, mOutAllocation);
mOutAllocation.copyTo(outputData);
mInAllocation.copyTo(inputData);
System.out.println("Debug: Verification " + Arrays.toString(verification));
System.out.println("Debug: outBuff " + Arrays.toString(outputData));
}
示例8: run
import android.renderscript.Allocation; //导入方法依赖的package包/类
public void run() {
RenderScript mRS = RenderScript.create(mCtx);
Allocation mInAllocation = Allocation.createSized(mRS, Element.F32_2(mRS), inputData.length/2);
mInAllocation.copyFrom(inputData);
Allocation mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
ScriptC_high_pass mScript = new ScriptC_high_pass(mRS, mRes, R.raw.high_pass);
mScript.set_gIn(mInAllocation);
mScript.set_gOut(mOutAllocation);
mScript.set_a(RC / (RC + dt));
//So far rendesrcipt seems to be able to detect this is a serial-like algorithm.
//If in your testing you start to get error change it back to the serial or linear restriction
mScript.forEach_root(mInAllocation, mOutAllocation);
// mScript.invoke_runRestricted(mScript, dt, RC);
mOutAllocation.copyTo(outputData);
mInAllocation.copyTo(inputData);
System.out.println("Debug: Verification " + Arrays.toString(verification));
System.out.println("Debug: outBuff " + Arrays.toString(outputData));
}