GPU Support

207 views
Skip to first unread message

joe...@google.com

unread,
Aug 11, 2017, 1:02:58 PM8/11/17
to bazel-discuss
Are there plans for possibly extracting the tensorflow GPU support (cuda,nvcc,clang) out to be reusable?

At first I tried to do it myself, but stopped when I realized somethings depended on tensorflow/core and wasn't as straightforward as I would of liked.

I did find
https://github.com/biolee/bazel_rule_cuda which seems like an attempt at that, but I ran into some issues.

Any thoughts on this? I would even *possibly* be willing to dedicate some time to make a canonical supported solution for nvidia/cuda compiling.

I also think there are 2 different issues. 1 is using the cuda libraries. 2. Is the toolchain for compiliation.

Thanks!

m...@m-sp.org

unread,
Oct 30, 2017, 3:35:43 AM10/30/17
to bazel-discuss
+1

I ran into the same issue! In my project, it would be as simple as running "nvcc" instead of "g++", and I already spent a few hours trying to understand how crosstool works.

Is there any easier way to do this? (Easy as in just adding a flag to the 'bazel' command or adding a line to my BUILD file or .bazelrc file.)

Marcel Hlopko

unread,
Oct 30, 2017, 3:39:41 AM10/30/17
to m...@m-sp.org, bazel-discuss
If I understand you correctly, then setting CC environment variable is enough. Check out our autoconfiguration script for details.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/66069d60-28cb-4c96-b7b0-b6ca21ee3064%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

m...@m-sp.org

unread,
Oct 30, 2017, 5:07:03 AM10/30/17
to bazel-discuss
Thanks for the fast reply
If I just set the CC environment variable, Bazel will pass invalid arguments to nvcc. E.g., nvcc does not understand "-fstack-protector" and stops right there.

I was looking at the autoconfiguration script, but I am not quite sure how to use it. Is there a working example somewhere?

Marcel Hlopko

unread,
Oct 30, 2017, 5:15:56 AM10/30/17
to m...@m-sp.org, bazel-discuss
So if it's not as simple as switching nvcc for g++, then you have multiple options:
* create a wrapper script that will remove unsupported flags. This is hackiest but also simplest solution.
* write your own crosstool. This is not fun but is actually doable. In ~ 2 weeks I'll update the wiki page (https://github.com/bazelbuild/bazel/wiki/Building-with-a-custom-toolchain) with more up to date and more precise instructions. Then the task should be simpler.
* write your own autoconfigure script. Here's the blog post about skylark repositories and their use for autoconfiguration: https://blog.bazel.build/2016/03/31/autoconfiguration.html


For more options, visit https://groups.google.com/d/optout.

Break Yang

unread,
Oct 30, 2017, 8:16:18 PM10/30/17
to bazel-discuss


On Monday, October 30, 2017 at 2:15:56 AM UTC-7, Marcel Hlopko wrote:
So if it's not as simple as switching nvcc for g++, then you have multiple options:
* create a wrapper script that will remove unsupported flags. This is hackiest but also simplest solution.
* write your own crosstool. This is not fun but is actually doable. In ~ 2 weeks I'll update the wiki page (https://github.com/bazelbuild/bazel/wiki/Building-with-a-custom-toolchain) with more up to date and more precise instructions. Then the task should be simpler.
Updating this wiki page would be extremely helpful! Thanks! 

Marcel Hlopko

unread,
Nov 3, 2017, 9:34:25 AM11/3/17
to Break Yang, bazel-discuss

Hyrum Wright

unread,
Nov 3, 2017, 12:27:34 PM11/3/17
to Marcel Hlopko, Break Yang, bazel-discuss
Thanks for posting this; it's super helpful.

A few of comments:
  • It would be nice if the steps were numbered, so that they would be easier to refer to.

  • toolchain/BUILD contains a filegroup() with the name of "emscripten" and a cc_toolchain_suite() with the name of "emscripten".  This would seem to violate the unique name policy, and in fact Bazel complains about this.

  • It would be nice if the complete end result was available and linked to from somewhere on the wiki page, so that we could check our work.  (Bonus points for including full contents at intermediate steps on the page, though I realize that might not work with the github formatting system.)

To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAFuL9GnZae_j_b-h5bDHMnduLBTRePqwn%3D61aJgQcaD87W0gew%40mail.gmail.com.

Marcel Hlopko

unread,
Nov 14, 2017, 4:57:04 PM11/14/17
to Hyrum Wright, Break Yang, bazel-discuss
Hi Hyrum,
thanks for the feedback!
1) Numbering is a good idea, will do so.
2) That is me being imprecise. You have to remove the 'emscripten' filegroup when you introduce `cc_toolchain_suite`. I updated the wiki.
3) That would indeed be nice, but I guess contributions welcome. I'll spend my free cycles on improving the docs more.

--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

ohad...@gmail.com

unread,
Apr 19, 2020, 9:34:42 AM4/19/20
to bazel-discuss
Hi,
I've stumbled on this 2 years old post as I am facing today a similar problem - I would like to compile cuda code using Bazel and I see that's is not straightforward. Before diving into crosstool, anyone here has managed to do so? Is there's a boilerplate code available?
Thanks,
Ohad

To unsubscribe from this group and stop receiving emails from it, send an email to bazel-...@googlegroups.com.
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages