Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ jobs:
- run: cd examples && bazelisk build --jobs=1 //if_cuda:main
- run: cd examples && bazelisk build --jobs=1 //if_cuda:main --enable_cuda=False
- run: bazelisk shutdown

# run some repo integration tests
- run: cd tests/integration && ./test_all.sh
- run: cd tests/hermeticity && ./test.sh

# Use Bazel 7
- run: echo "USE_BAZEL_VERSION=7.5.0" >> $GITHUB_ENV
Expand Down
16 changes: 16 additions & 0 deletions cuda/private/toolchain_configs/nvcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,21 @@ def _impl(ctx):
],
)

# NOTE: this only works on compiler newer than 12.9
nvcc_fixed_random_seed_feature = feature(
name = "nvcc_fixed_random_seed",
enabled = True,
flag_sets = [
flag_set(
actions = [
ACTION_NAMES.cuda_compile,
ACTION_NAMES.device_link,
],
flag_groups = [flag_group(flags = ["--frandom-seed=%{output_file}"])],
),
] if nvcc_version_ge(ctx, 12, 9) else [],
)

cuda_device_debug_feature = feature(
name = "cuda_device_debug",
flag_sets = [
Expand Down Expand Up @@ -601,6 +616,7 @@ def _impl(ctx):
nvcc_allow_unsupported_compiler_feature,
nvcc_relaxed_constexpr_feature,
nvcc_extended_lambda_feature,
nvcc_fixed_random_seed_feature,
cuda_device_debug_feature,
]

Expand Down
16 changes: 16 additions & 0 deletions cuda/private/toolchain_configs/nvcc_msvc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,21 @@ def _impl(ctx):
],
)

# NOTE: this only works on compiler newer than 12.9
nvcc_fixed_random_seed_feature = feature(
name = "nvcc_fixed_random_seed",
enabled = True,
flag_sets = [
flag_set(
actions = [
ACTION_NAMES.cuda_compile,
ACTION_NAMES.device_link,
],
flag_groups = [flag_group(flags = ["--frandom-seed=%{output_file}"])],
),
] if nvcc_version_ge(ctx, 12, 9) else [],
)

cuda_device_debug_feature = feature(
name = "cuda_device_debug",
flag_sets = [
Expand Down Expand Up @@ -646,6 +661,7 @@ def _impl(ctx):
nvcc_allow_unsupported_compiler_feature,
nvcc_extended_lambda_feature,
nvcc_relaxed_constexpr_feature,
nvcc_fixed_random_seed_feature,
cuda_device_debug_feature,
]

Expand Down
13 changes: 13 additions & 0 deletions tests/hermeticity/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@rules_cuda//cuda:defs.bzl", "cuda_binary", "cuda_library")

cuda_library(
name = "cuda_lib",
srcs = ["lib.cu"],
hdrs = ["lib.h"],
)

cuda_binary(
name = "cuda_test",
srcs = ["main.cu"],
deps = [":cuda_lib"],
)
26 changes: 26 additions & 0 deletions tests/hermeticity/lib.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "lib.h"
#include <iostream>

namespace {
int helper_function(OptionB method) {
if (method == OptionB::B) {
return 1;
}

return 1;
}
} // namespace

template <class T> bool process(OptionA format, OptionB resizeMethod) {
if (format == OptionA::A) {
// The implementation doesn't matter, just the call to the function
// in the anonymous namespace.
helper_function(resizeMethod);
return true;
}

return false;
}

template bool process<unsigned char>(OptionA format,
OptionB resizeMethod);
14 changes: 14 additions & 0 deletions tests/hermeticity/lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef GENERIC_LIB_H
#define GENERIC_LIB_H

enum class OptionA {
A,
};

enum class OptionB {
B,
};

template <class T> bool process(OptionA format, OptionB method);

#endif // GENERIC_LIB_H
6 changes: 6 additions & 0 deletions tests/hermeticity/main.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "lib.h"

int main() {
process<unsigned char>(OptionA::A, OptionB::B);
return 0;
}
27 changes: 27 additions & 0 deletions tests/hermeticity/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

set -euo pipefail

file=$(bazel info execution_root)/$(bazel cquery --output=files :cuda_test)

bazel build :cuda_test
build_output1=$(strings ${file})

bazel clean

bazel build :cuda_test
build_output2=$(strings ${file})

diff_output=$(diff -u <(echo "$build_output1") <(echo "$build_output2") --color=always || true)

if [[ -n "$diff_output" ]]; then
echo -e "${RED}ERROR: Build outputs are not hermetic (differences detected):${NC}"
echo "$diff_output"
exit 1
else
echo -e "${GREEN}SUCCESS: Build outputs are hermetic (no differences)${NC}"
fi
Loading