Skip to content

Commit

Permalink
Merge branch 'main' into remote_toolchain_clean
Browse files Browse the repository at this point in the history
  • Loading branch information
jsharpe authored Jul 14, 2023
2 parents 0bc80db + 555f88f commit ff0d981
Show file tree
Hide file tree
Showing 44 changed files with 751 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build --enable_cuda=True
build:clang --repo_env=CC=clang
build:clang --//cuda:compiler=clang

# https://github.com/cloudhan/rules_cuda/issues/1
# https://github.com/bazel-contrib/rules_cuda/issues/1
build --ui_event_filters=-INFO

common:bzlmod --enable_bzlmod
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.1
6.2.1
61 changes: 36 additions & 25 deletions .github/workflows/build-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,78 @@ on:

jobs:
test:
name: "Test Examples Build (CUDA ${{ matrix.cuda-version }} on ${{ matrix.os }})"
runs-on: ${{ matrix.os }}
name: "Test Examples Build (CUDA ${{ matrix.cases.cuda-version }} on ${{ matrix.cases.os }})"
runs-on: ${{ matrix.cases.os }}
timeout-minutes: 60
strategy:
matrix:
os:
- ubuntu-18.04
- windows-2019
cuda-version:
- 10.1.243
- 11.2.2
- 11.6.2
cases:
- { os: "ubuntu-20.04", cuda-version: "11.2.2", source: "nvidia" }
- { os: "ubuntu-20.04", cuda-version: "11.6.2", source: "nvidia" }
- {
os: "ubuntu-22.04",
cuda-version: "11.5.1-1ubuntu1",
source: "ubuntu",
}
- { os: "windows-2019", cuda-version: "10.1.243", source: "nvidia" }
- { os: "windows-2019", cuda-version: "11.6.2", source: "nvidia" }
steps:
- uses: actions/checkout@v3

- uses: bazelbuild/setup-bazelisk@v2
- name: Mount bazel cache
if: ${{ !startsWith(matrix.os, 'windows') }}
if: ${{ !startsWith(matrix.cases.os, 'windows') }}
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: bazel-${{ matrix.os }}-cuda-${{ matrix.cuda-version }}-${{ hashFiles('.bazelversion') }}
key: bazel-${{ matrix.cases.os }}-cuda-${{ matrix.cases.cuda-version }}-${{ hashFiles('.bazelversion') }}

- name: Install CUDA (Linux)
- name: Install CUDA (NVIDIA, Linux)
uses: Jimver/cuda-toolkit@v0.2.10
if: ${{ !startsWith(matrix.os, 'windows') }}
if: ${{ !startsWith(matrix.cases.os, 'windows') && matrix.cases.source == 'nvidia' }}
with:
cuda: ${{ matrix.cuda-version }}
cuda: ${{ matrix.cases.cuda-version }}
sub-packages: '["nvcc", "cudart-dev"]'
method: network
- name: Show bin, include, lib (Linux)
if: ${{ !startsWith(matrix.os, 'windows') }}
- name: Show bin, include, lib (NVIDIA, Linux)
if: ${{ !startsWith(matrix.cases.os, 'windows') && matrix.cases.source == 'nvidia' }}
run: |
tree ${CUDA_PATH}/bin
tree ${CUDA_PATH}/include
tree ${CUDA_PATH}/lib64
- name: Install CUDA (Ubuntu)
if: ${{ !startsWith(matrix.cases.os, 'windows') && matrix.cases.source == 'ubuntu' }}
run: |
sudo apt-get update
sudo apt-get install -y nvidia-cuda-dev=${{ matrix.cases.cuda-version }} nvidia-cuda-toolkit=${{ matrix.cases.cuda-version }} gcc-9 g++-9
export CC=gcc-9
export CXX=g++-9
echo "CC=gcc-9" >> $GITHUB_ENV
echo "CXX=g++-9" >> $GITHUB_ENV
- name: Install CUDA (Windows)
uses: Jimver/cuda-toolkit@v0.2.10
if: ${{ startsWith(matrix.os, 'windows') }}
if: ${{ startsWith(matrix.cases.os, 'windows') }}
with:
cuda: ${{ matrix.cuda-version }}
cuda: ${{ matrix.cases.cuda-version }}
sub-packages: '["nvcc", "cudart"]'
method: network
- name: Show bin, include, lib64 (Windows)
if: ${{ startsWith(matrix.os, 'windows') }}
if: ${{ startsWith(matrix.cases.os, 'windows') }}
run: |
tree /F $env:CUDA_PATH/bin
tree /F $env:CUDA_PATH/include
tree /F $env:CUDA_PATH/lib/x64
- name: Set Visual Studio Environment (Windows)
if: ${{ startsWith(matrix.os, 'windows') }}
if: ${{ startsWith(matrix.cases.os, 'windows') }}
run: .github/workflows/Set-VSEnv.ps1 2019

- run: bazelisk build @rules_cuda_examples//basic:main
- run: bazelisk build @rules_cuda_examples//rdc:main
- run: bazelisk build @rules_cuda_examples//basic:all
- run: bazelisk build @rules_cuda_examples//rdc:all
- run: bazelisk build @rules_cuda_examples//if_cuda:main
- run: bazelisk build @rules_cuda_examples//if_cuda:main --enable_cuda=False

- run: cd examples && bazelisk build //basic:main --config=bzlmod
- run: cd examples && bazelisk build //rdc:main --config=bzlmod
- run: cd examples && bazelisk build //basic:all --config=bzlmod
- run: cd examples && bazelisk build //rdc:all --config=bzlmod
- run: cd examples && bazelisk build //if_cuda:main --config=bzlmod
- run: cd examples && bazelisk build //if_cuda:main --enable_cuda=False --config=bzlmod

Expand Down
32 changes: 0 additions & 32 deletions .github/workflows/docs-tests.yaml

This file was deleted.

79 changes: 79 additions & 0 deletions .github/workflows/github-pages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Generate docs

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
pages:
runs-on: ubuntu-latest
strategy:
matrix:
docs:
# { ref: <branch/tag name>, name: <docs drop down entry> }
- { ref: main, name: latest }
steps:
- uses: actions/checkout@v3
if: ${{ matrix.docs.ref == 'main' }}
- uses: actions/checkout@v3
with:
ref: ${{ matrix.docs.ref }}
if: ${{ matrix.docs.ref != 'main' }}

- uses: bazelbuild/setup-bazelisk@v2
- name: Mount bazel cache
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: bazel-gen-docs-${{ matrix.docs.ref }}

- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pip

- name: Generate docs
run: bash ./build-docs.sh
env:
CI: 1
working-directory: ${{ github.workspace }}/docs

- run: bazelisk shutdown

- uses: actions/upload-artifact@v3
with:
name: "${{ matrix.docs.name }}"
path: ${{ github.workspace }}/docs/site/
if-no-files-found: error
if: ${{ github.event_name != 'pull_request' }}

publish:
needs: pages
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
path: ${{ github.workspace }}/docs/generated
- name: Inspect docs site directory structure
run: find ${{ github.workspace }}/docs/generated -maxdepth 2

- uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: |
pip install packaging==23.*
python versioning.py generated/
working-directory: ${{ github.workspace }}/docs
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/generated
force_orphan: true
22 changes: 22 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: pre-commit

on:
push:
branches:
- main
pull_request:

jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: set PY
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/action@v3.0.0
- uses: pre-commit-ci/lite-action@v1.0.1
if: always()
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os:
- ubuntu-18.04
- ubuntu-22.04
cuda-version:
- 11.6.2
steps:
Expand Down Expand Up @@ -71,4 +71,4 @@ jobs:
upload_url: ${{ steps.rules_cuda_release.outputs.upload_url }}
asset_name: rules_cuda-${{ env.RELEASE_VERSION }}.tar.gz
asset_path: ${{ github.workspace }}/.github/rules_cuda.tar.gz
asset_content_type: application/gzip
asset_content_type: application/gzip
2 changes: 1 addition & 1 deletion .github/workflows/utilities-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
os:
- ubuntu-20.04
- windows-latest
- windows-2019
bazel-version:
- 5.0.0
- 5.2.0
Expand Down
7 changes: 3 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ default_stages: [commit]

repos:
# Check formatting and lint for starlark code
- repo: https://github.com/keith/pre-commit-buildifier
rev: 4.0.1.1
- repo: https://github.com/garymm/bazel-buildifier-pre-commit-hooks
rev: v6.1.2
hooks:
- id: buildifier
# - id: buildifier-lint
- id: bazel-buildifier
# Enforce that commit messages allow for later changelog generation
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.18.0
Expand Down
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module(
version = "0.0.0",
)

bazel_dep(name = "bazel_skylib", version = "1.2.1")

bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "platforms", version = "0.0.6")

toolchain = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain")
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ register_detected_cuda_toolchains()
ensure the host compiler is available. On windows, this means that you will also need to set the environment variable
`BAZEL_VC` properly.

[`detect_cuda_toolkit`](https://github.com/cloudhan/rules_cuda/blob/f534446357/cuda/private/repositories.bzl#L44-L57)
and [`detect_clang`](https://github.com/cloudhan/rules_cuda/blob/f534446357/cuda/private/repositories.bzl#L129-L143)
[`detect_cuda_toolkit`](https://github.com/bazel-contrib/rules_cuda/blob/5633f0c0f7/cuda/private/repositories.bzl#L28-L58)
and [`detect_clang`](https://github.com/bazel-contrib/rules_cuda/blob/5633f0c0f7/cuda/private/repositories.bzl#L143-L166)
determains how the toolchains are detected.

### Rules
Expand Down Expand Up @@ -67,7 +67,7 @@ bazel build --cuda_archs=compute_61:compute_61,sm_61

- `@rules_cuda//cuda:archs`

Select the cuda archs to support. See [cuda_archs specification DSL grammar](https://github.com/cloudhan/rules_cuda/blob/f534446357/cuda/private/providers.bzl#L43-L65).
Select the cuda archs to support. See [cuda_archs specification DSL grammar](https://github.com/bazel-contrib/rules_cuda/blob/5633f0c0f7/cuda/private/rules/flags.bzl#L14-L44).

- `@rules_cuda//cuda:compiler`

Expand All @@ -81,13 +81,19 @@ bazel build --cuda_archs=compute_61:compute_61,sm_61

Set the default cudart to link, for example, `--@rules_cuda//cuda:runtime=@local_cuda//:cuda_runtime_static` link the static cuda runtime.

- `--features=cuda_device_debug`

Sets nvcc flags to enable debug information in device code.
Currently ignored for clang, where `--compilation_mode=debug` applies to both
host and device code.

## Examples

Checkout the examples to see if it fits your needs.

See [examples](./examples) for basic usage.

See [cloudhan/rules_cuda_examples](https://github.com/cloudhan/rules_cuda_examples) for extended real world projects.
See [rules_cuda_examples](https://github.com/cloudhan/rules_cuda_examples) for extended real world projects.

## Known issue

Expand Down
7 changes: 3 additions & 4 deletions cuda/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ load(
"@bazel_skylib//rules:common_settings.bzl",
"bool_flag",
"string_flag",
"string_list_flag",
)
load("//cuda/private:rules/flags.bzl", "cuda_archs_flag")
load("//cuda/private:rules/flags.bzl", "cuda_archs_flag", "repeatable_string_flag")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -67,9 +66,9 @@ config_setting(
)

# Command line flag for copts to add to cuda_library() compile command.
string_list_flag(
repeatable_string_flag(
name = "copts",
build_setting_default = [],
build_setting_default = "",
)

# Command line flag to specify the CUDA runtime. Use this target as CUDA
Expand Down
4 changes: 3 additions & 1 deletion cuda/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Core rules for building CUDA projects.
"""

load("//cuda/private:providers.bzl", _CudaArchsInfo = "CudaArchsInfo", _cuda_archs = "cuda_archs")
load("//cuda/private:os_helpers.bzl", _if_linux = "if_linux", _if_windows = "if_windows")
load("//cuda/private:os_helpers.bzl", _cc_import_versioned_sos = "cc_import_versioned_sos", _if_linux = "if_linux", _if_windows = "if_windows")
load("//cuda/private:rules/cuda_objects.bzl", _cuda_objects = "cuda_objects")
load("//cuda/private:rules/cuda_library.bzl", _cuda_library = "cuda_library")
load("//cuda/private:rules/cuda_toolkit.bzl", _cuda_toolkit = "cuda_toolkit")
Expand Down Expand Up @@ -33,3 +33,5 @@ cuda_library = _cuda_library

if_linux = _if_linux
if_windows = _if_windows

cc_import_versioned_sos = _cc_import_versioned_sos
2 changes: 1 addition & 1 deletion cuda/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("//cuda/private:repositories.bzl", "local_cuda")

cuda_toolkit = tag_class(attrs = {
"name": attr.string(doc = "Name for the toolchain repository", default = "local_cuda"),
"toolkit_path": attr.string(doc = "Path to the CUDA SDK"),
"toolkit_path": attr.string(doc = "Path to the CUDA SDK, if empty the environment variable CUDA_PATH will be used to deduce this path."),
})

def _init(module_ctx):
Expand Down
Loading

0 comments on commit ff0d981

Please sign in to comment.