Skip to content

Cross-compilation support #395

@ahans

Description

@ahans

First up, thanks for this great project, we've been using it successfully for quite a while now!

I'd like to add support for cross compilation for Jetson/aarch64 using redist.json as a source. I have hacked already a bit and have a version that can at least compile examples/basic. The libraries still need some work, but before I put that in, I'd like to hear if there are already thoughts on how to accomplish that. I guess I could finish my version and it'd be fine for my needs, but ideally I'd like to contribute a PR so that others benefit from this as well.

Here's a rough outline of what I did:

  • Extend redist_json_helper so that it does not filter for x86_64, but also includes aarch64. I then added a field arch to the struct that gets appended to specs for each component.
  • Then in _redist_json_impl in cuda/extensions.bzl, I modify the specs list a bit so that for each component I have an entry where there are dicts urls, shas256, and strip_prefixes that each have two keys, x86_64 and aarch64.
  • The result gets fed into a new repository rule cuda_multi_platform_component which iterates over the keys, effectively calling download_and_extract twice.
  • Finally, the templates needed a bit of work to have targets for each architecture that are used by a top-level target (such as cuda_runtime), which has a bunch of selects, very similar to what is currently present to support both Windows and Linux.

As I said, this seems to be working, however, I'm not certain which usecases I broke along the way. Also, some cleanup and refactoring would be necessary to avoid redundancy.

One thing that complicates things a bit is that for most things I need the target architecture archive, but nvcc I need for the host. Just like clang, you only need to care about the host architecture here. In the repository rule I extract archives into x86_64 and aarch64 subdirectories. For nvcc I added some special handling, there I also create some symlinks to the directories in x86_64, so that all files are available where current main expects them.

Another thing I thought about was having subdirectories only in lib, but then I'd have to modify the original archive structure, which is something I'd like to avoid.

Initially I also thought about having a repository per architecture, but then I'd need a new place for the select. Ultimately, I want to be able to depend on @cuda//:cublas in my top-level target and it picks the correct libraries automatically depending on the architecture I'm building for.

I only need support for Linux x86_64 as the host and x86_64 and aarch64 as targets. However, AFAIU, support for a Linux aarch64 host would be possible with the redist.json archives, but would complicate the work required for rules_cuda even further.

If the overall approach outlined above sounds reasonable, I would suggest to start with the Linux x86_64 -> aarch64 support without breaking existing Linux x86_64 -> Linux x86_64 and Windows -> Windows support.

Another thing; I only care about bzlmod. Not sure how much of a priority new features for workspace are here.

Anyway, let me know what you think! Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions