Commit b83873cd authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

minor updates

parent 479ca3da
...@@ -80,6 +80,62 @@ public class tfhello{ ...@@ -80,6 +80,62 @@ public class tfhello{
return ptr; return ptr;
} }
public static int CallableOptionsToByteArray1(){
String gpuDeviceName = "/job:localhost/replica:0/task:0/device:GPU:0";
CallableOptions callableOpts = CallableOptions.newBuilder()
.addFetch("output1:0")
.addFeed("input1:0")
.putFeedDevices("input1:0", gpuDeviceName)
.build();
System.out.println(callableOpts);
byte[] boits = callableOpts.toByteArray();
System.out.print("{");
for (int i=0; i< boits.length; ++i) {
if (i==(boits.length-1)) {
System.out.print(String.format("0x%02x", boits[i]));
}else{
System.out.print(String.format("0x%02x, ", boits[i]));
}
}
System.out.println("}");
return 0;
}
public static int CallableOptionsToByteArray2(){
String gpuDeviceName = "/job:localhost/replica:0/task:0/device:GPU:0";
CallableOptions callableOpts = CallableOptions.newBuilder()
.addFetch("output1:0")
.addFeed("input1:0")
.setFetchSkipSync(true)
.putFetchDevices("output1:0", gpuDeviceName)
.build();
//.fetch_skip_sync = false;
System.out.println(callableOpts);
byte[] boits = callableOpts.toByteArray();
System.out.print("{");
for (int i=0; i< boits.length; ++i) {
if (i==(boits.length-1)) {
System.out.print(String.format("0x%02x", boits[i]));
}else{
System.out.print(String.format("0x%02x, ", boits[i]));
}
}
System.out.println("}");
return 0;
}
public static void main(String[] args) throws Exception{ public static void main(String[] args) throws Exception{
// CUDA test start // CUDA test start
...@@ -154,7 +210,7 @@ public class tfhello{ ...@@ -154,7 +210,7 @@ public class tfhello{
System.out.println("Test 3 start\n - Print TF version"); System.out.println("Test 3 start\n - Print TF version");
System.out.println(TensorFlow.version()); System.out.println(TensorFlow.version());
System.out.println("Test 3 end\n"); System.out.println("Test 3 end\n");
//System.out.println("Test 4 start\n - Test simple custom JNI function added to TF"); //System.out.println("Test 4 start\n - Test simple custom JNI function added to TF");
//System.out.println(TensorFlow.elphelVersion()); //System.out.println(TensorFlow.elphelVersion());
//System.out.println("Test 4 end\n"); //System.out.println("Test 4 end\n");
...@@ -178,10 +234,22 @@ public class tfhello{ ...@@ -178,10 +234,22 @@ public class tfhello{
//.setAttr("dtype",DataType.UINT8) //.setAttr("dtype",DataType.UINT8)
//.setAttr("dtype",DataType.INT64) //.setAttr("dtype",DataType.INT64)
.build(); .build();
Operation k = g.opBuilder("Const", "array_const")
.setAttr("dtype", DataType.FLOAT)
.setAttr("value", Tensor.<Float>create((float) 2.0, Float.class))
.build();
/*
Operation z = g.opBuilder("Identity", "array_tensor_out") Operation z = g.opBuilder("Identity", "array_tensor_out")
.addInput(x.output(0)) .addInput(x.output(0))
.build(); .build();
*/
Operation z = g.opBuilder("Mul", "array_tensor_out")
.addInput(x.output(0))
.addInput(k.output(0))
.build();
// unit8 // unit8
//Tensor t = Tensor.create(px_in_uint8); //Tensor t = Tensor.create(px_in_uint8);
...@@ -217,16 +285,17 @@ public class tfhello{ ...@@ -217,16 +285,17 @@ public class tfhello{
System.out.println("Output from the first run: "); System.out.println("Output from the first run: ");
System.out.println(Arrays.toString(obuf)); System.out.println(Arrays.toString(obuf));
// natively got GPU device name to insert into options // natively got GPU device name to insert into options
// it's the same all the time // it's the same all the time
String gpuDeviceName = s.GPUDeviceName(); String gpuDeviceName = s.GPUDeviceName();
// GPU allocation: dims must be power of 2? // GPU allocation: dims must be power of 2?
Tensor t3 = Tensor.createGPU(new long[]{256},DataType.FLOAT); Tensor t3 = Tensor.createGPU(new long[]{256},DataType.FLOAT);
t3.isGPUTensor();
t3.setValueGPU(px_in_float);
//System.out.println(t2.nativeRef); //System.out.println(t2.nativeRef);
// Let's check what happended // Let's check what happened
long t3_gpuptr = t3.GPUPointer(); long t3_gpuptr = t3.GPUPointer();
// Print address // Print address
//System.out.println("Pointer address: "+String.format("0x%08x", t3_gpuptr)); //System.out.println("Pointer address: "+String.format("0x%08x", t3_gpuptr));
...@@ -272,8 +341,11 @@ public class tfhello{ ...@@ -272,8 +341,11 @@ public class tfhello{
.addFeed("array_tensor_in:0") .addFeed("array_tensor_in:0")
.putFeedDevices("array_tensor_in:0", gpuDeviceName) .putFeedDevices("array_tensor_in:0", gpuDeviceName)
.build(); .build();
System.out.println(callableOpts); //CallableOptionsToByteArray1();
//CallableOptionsToByteArray2();
// callable handle // callable handle
long feed_gpu_fetch_cpu = s.makeCallable(callableOpts.toByteArray()); long feed_gpu_fetch_cpu = s.makeCallable(callableOpts.toByteArray());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment