Replicating the function of tf.config.list_physical_devices

46 views
Skip to first unread message

Tom B

unread,
Nov 5, 2020, 12:35:38 PM11/5/20
to SIG JVM
Hello SIG-members,

is there a way to access the list of physical devices provided through the function mentioned in the title in Java? list_physical_devices
The use-case I'm currently trying to solve:
- I want the user of my application to be able to select the device(s) on which Tensorflow is going to run
- (optional) I also want to check the availability of GPUs, to ensure that CUDA is correctly installed. I reason that they should not be available to Tensorflow if anything is missing, correct me if I am wrong on that.

Karl Lessard

unread,
Nov 7, 2020, 8:38:14 AM11/7/20
to Tom B, SIG JVM
Hi Tom,

There is an internal endpoint that should return you the same list as in Python. There are a few other endpoints in that same file related to devices that you can take a look at.

These endpoints though are not meant to be used directly by the end-users and should be wrapped instead within a Java-friendly API. The wrapper for such an endpoint has not been added yet. If they work for you, would you be interested to make that contribution? (maybe something like `List<DeviceSpec> TensorFlow.listDevices(DeviceType... deviceType)` or any better suggestion?)

Thanks,
Karl

--
You received this message because you are subscribed to the Google Groups "SIG JVM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jvm+uns...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/jvm/067d8f39-060d-41d9-a485-1fb1db913060n%40tensorflow.org.

Tom B

unread,
Nov 10, 2020, 10:15:46 AM11/10/20
to SIG JVM, karl.l...@gmail.com, SIG JVM, Tom B
Thanks for the pointers Karl! I'll gladly make that contribution as soon as I find a good timeslot to get to it, as this topic is currently further down the priority list for me. No promises, but I think I can go back to it at the start of december.

Best,
Tom

Tom B

unread,
Dec 14, 2020, 7:53:39 AM12/14/20
to SIG JVM
Hi everyone,

I'm having a hard time trying to unterstand how the wrapping and converting of objects works, especially in regards to converting from TF_DeviceList to List<DeviceSpec>.
Is anyone willing to give me some pointers or has time for a short bit of partner-coding to get me started with the project?

Best,
Tom

Samuel Audet

unread,
Dec 15, 2020, 1:14:29 AM12/15/20
to Tom B, SIG JVM
Hi, Tom,

TFE_ContextListDevices() appears to get called only in this function from Python:
I think we basically just need to port that function to Java :)

There's also code in Go and C++ calling it:
If there is anything unclear, please let me know!

Samuel
Reply all
Reply to author
Forward
0 new messages