Loading src/main/java/tfhello.java +77 −5 Original line number Original line Diff line number Diff line Loading @@ -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 Loading Loading @@ -179,9 +235,21 @@ public class tfhello{ //.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); Loading Loading @@ -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)); Loading Loading @@ -273,7 +342,10 @@ public class tfhello{ .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()); Loading Loading
src/main/java/tfhello.java +77 −5 Original line number Original line Diff line number Diff line Loading @@ -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 Loading Loading @@ -179,9 +235,21 @@ public class tfhello{ //.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); Loading Loading @@ -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)); Loading Loading @@ -273,7 +342,10 @@ public class tfhello{ .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()); Loading