rules_cuda icon indicating copy to clipboard operation
rules_cuda copied to clipboard

Why `@rules_cuda//cuda:runtime` flag rather than respecting `--dynamic_mode`

Open garymm opened this issue 2 years ago • 5 comments
trafficstars

Bazel already has a flag (--dynamic_mode) to allow controlling of static vs dynamic linking. I think it's feasible to apply this to the cuda runtime. Why not use this flag? It's surprising that there's a separate flag and that the bazel flag is not respected.

If you're OK with switching to use the built-in --dynamic_mode I'd be happy to open a PR to implement the change. Thanks!

garymm avatar Jul 03 '23 21:07 garymm

This is from https://github.com/bazel-contrib/rules_cuda/blob/152bbbc9a8680d18b38ca4fba2f9bdb09ee68862/cuda/BUILD#L91-L103, this repo originally is a subtree of tf_runtime and then a full rewrite is carried out starts (with an independent source tree root).

cloudhan avatar Jul 04 '23 00:07 cloudhan

@cloudhan are you OK with me removing the flag and just relying on --dynamic_mode? Or if not, then having the default be to respect --dynamic_mode?

garymm avatar Jul 05 '23 17:07 garymm

I don't know the reason behind it actually, so let's keep it as is for now. Maybe @chsigg can explain it a bit?

cloudhan avatar Jul 05 '23 17:07 cloudhan

The flag is also introduced to inject a different CUDA runtime, e.g. one that dynamically loads the real CUDA runtime and forwards the calls. That can be independent though of (by default) dynamically switching between linking against static or dynamic runtime. I don't know how to dynamically switch between the two based on --dynamic_mode. You could probably use cc_import(), but you might need to wrap that in a cc_library() still for the existing linkopts arguments. This might be worthwhile doing, although NVIDIA strongly advises against linking dynamic CUDA runtime.

chsigg avatar Jul 06 '23 12:07 chsigg

If you assign this to me I can work on making it respect --dynamic_mode by default, and we can leave the flag to override.

garymm avatar Jul 06 '23 21:07 garymm