Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tfhello
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Oleg Dzhimiev
tfhello
Commits
b83873cd
Commit
b83873cd
authored
Apr 01, 2020
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor updates
parent
479ca3da
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
5 deletions
+77
-5
tfhello.java
src/main/java/tfhello.java
+77
-5
No files found.
src/main/java/tfhello.java
View file @
b83873cd
...
@@ -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
...
@@ -179,9 +235,21 @@ public class tfhello{
...
@@ -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);
...
@@ -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 happen
d
ed
// 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));
...
@@ -273,7 +342,10 @@ public class tfhello{
...
@@ -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
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment