diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 05af54d9a3..8b13789179 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -1,79 +1 @@ -steps: - - label: "CUDA Julia v{{matrix.version}}" - matrix: - setup: - version: - - "1.10" - - "1.11" - - "1.12" - plugins: - - JuliaCI/julia#v1: - version: "{{matrix.version}}" - agents: - queue: "cuda" - if: build.message !~ /\[skip tests\]/ - timeout_in_minutes: 60 - commands: | - echo "--- Setup Julia packages" - JULIA_PKG_PRECOMPILE_AUTO="false" julia --color=yes -e ' - using Pkg - pkgs = [PackageSpec(; path) for path in (".", "lib/EnzymeCore", "lib/EnzymeTestUtils")] - Pkg.develop(pkgs) - Pkg.add(PackageSpec(; name="CUDA", version="6"))' || exit 3 - echo "+++ Run tests" - julia --color=yes test/cuda.jl - env: - JULIA_PKG_SERVER_REGISTRY_PREFERENCE: eager - -# - label: "AMDGPU Julia v{{matrix.version}}" -# matrix: -# setup: -# version: -# - "1.10" -# plugins: -# - JuliaCI/julia#v1: -# version: "{{matrix.version}}" -# agents: -# queue: "rocm" -# if: build.message !~ /\[skip tests\]/ -# timeout_in_minutes: 60 -# commands: | -# echo "--- Setup Julia packages" -# julia --color=yes -e ' -# using Pkg -# pkgs = [PackageSpec(; path) for path in (".", "lib/EnzymeCore", "lib/EnzymeTestUtils")] -# push!(pkgs, PackageSpec(; name="AMDGPU")) -# Pkg.develop(pkgs)' || exit 3 -# -# echo "+++ Run tests" -# julia --color=yes test/amdgpu.jl -# env: -# JULIA_PKG_SERVER_REGISTRY_PREFERENCE: eager -# -# - label: "Metal Julia v{{matrix.version}}" -# matrix: -# setup: -# version: -# - "1.10" -# plugins: -# - JuliaCI/julia#v1: -# version: "{{matrix.version}}" -# agents: -# queue: "juliaecosystem" -# os: "macos" -# arch: "aarch64" -# if: build.message !~ /\[skip tests\]/ -# timeout_in_minutes: 60 -# commands: | -# echo "--- Setup Julia packages" -# julia --color=yes -e ' -# using Pkg -# pkgs = [PackageSpec(; path) for path in (".", "lib/EnzymeCore", "lib/EnzymeTestUtils")] -# push!(pkgs, PackageSpec(; name="Metal")) -# Pkg.develop(pkgs)' || exit 3 -# -# echo "+++ Run tests" -# julia --color=yes test/metal.jl -# env: -# JULIA_PKG_SERVER_REGISTRY_PREFERENCE: eager diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b3e095e483..ccd594f8cf 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -45,8 +45,6 @@ jobs: - '1.12' - 'nightly' os: - - ubuntu-24.04 - - macOS-latest - windows-latest llvm_args: - '' @@ -59,44 +57,6 @@ jobs: - os: windows-latest arch: default libEnzyme: local - include: - - os: ubuntu-24.04 - arch: x86 - libEnzyme: packaged - version: '1.10' - assertions: false - - os: ubuntu-24.04 - arch: default - libEnzyme: packaged - version: '1.10' - assertions: true - - os: ubuntu-24.04 - arch: default - libEnzyme: packaged - version: '1.11' - assertions: true - - os: ubuntu-24.04 - arch: default - libEnzyme: packaged - version: '1.12' - assertions: true - - os: ubuntu-24.04 - arch: default - libEnzyme: packaged - version: '1.13' - assertions: true - - os: ubuntu-24.04 - arch: default - libEnzyme: packaged - version: '1.10' - assertions: true - llvm_args: '--opaque-pointers' - - os: ubuntu-24.04 - arch: default - libEnzyme: packaged - version: '1.11' - assertions: false - llvm_args: '--opaque-pointers' steps: - uses: actions/checkout@v7 - uses: julia-actions/setup-julia@v3 @@ -177,115 +137,3 @@ jobs: files: lcov.info token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: false # or true if you want CI to fail when Codecov fails - - enzymetestutils: - timeout-minutes: 60 - name: EnzymeTestUtils - Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ matrix.libEnzyme }} libEnzyme - ${{ github.event_name }} - runs-on: ${{ matrix.os }} - continue-on-error: ${{ matrix.version == 'nightly' }} - env: - JULIA_PROJECT: "lib/EnzymeTestUtils" - strategy: - fail-fast: false - matrix: - version: - - '1.10' - - '1.11' - - '1.12' - - 'nightly' - os: - - ubuntu-latest - arch: - - default - libEnzyme: [packaged] - steps: - - uses: actions/checkout@v7 - - uses: julia-actions/setup-julia@v3 - with: - version: ${{ matrix.version }} - arch: ${{ matrix.arch }} - - uses: julia-actions/cache@v3 - - name: setup EnzymeTestUtils - shell: julia --color=yes {0} - id: setup_testutils - continue-on-error: ${{ matrix.version == 'nightly' }} - run: | - using Pkg - Pkg.develop([PackageSpec(; path) for path in (".", "lib/EnzymeCore")]) - Pkg.instantiate() - env: - JULIA_PKG_SERVER_REGISTRY_PREFERENCE: eager - - name: Run the tests - if: matrix.version != 'nightly' || steps.setup_testutils.outcome == 'success' - continue-on-error: ${{ matrix.version == 'nightly' }} - id: run_tests - shell: julia --color=yes {0} - run: | - using Pkg - Pkg.test("EnzymeTestUtils"; coverage=true) - - uses: julia-actions/julia-processcoverage@v1 - if: matrix.version != 'nightly' || steps.run_tests.outcome == 'success' - with: - directories: lib/EnzymeTestUtils/src - - uses: codecov/codecov-action@v7 - if: matrix.version != 'nightly' || steps.run_tests.outcome == 'success' - with: - files: lcov.info - token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: false # or true if you want CI to fail when Codecov fails - - enzymecore: - timeout-minutes: 20 - name: EnzymeCore - Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ matrix.libEnzyme }} libEnzyme - ${{ github.event_name }} - runs-on: ${{ matrix.os }} - continue-on-error: ${{ matrix.version == 'nightly' }} - env: - JULIA_PROJECT: "lib/EnzymeCore" - strategy: - fail-fast: false - matrix: - version: - - '1.10' - - '1.11' - - '1.12' - - 'nightly' - os: - - ubuntu-latest - arch: - - default - libEnzyme: [packaged] - steps: - - uses: actions/checkout@v7 - - uses: julia-actions/setup-julia@v3 - with: - version: ${{ matrix.version }} - arch: ${{ matrix.arch }} - - uses: julia-actions/cache@v3 - - name: setup EnzymeCore - shell: julia --color=yes {0} - id: setup_testutils - continue-on-error: ${{ matrix.version == 'nightly' }} - run: | - using Pkg - Pkg.develop([PackageSpec(; path) for path in (".",)]) - Pkg.instantiate() - env: - JULIA_PKG_SERVER_REGISTRY_PREFERENCE: eager - - name: Run the tests - if: matrix.version != 'nightly' || steps.setup_testutils.outcome == 'success' - continue-on-error: ${{ matrix.version == 'nightly' }} - id: run_tests - shell: julia --color=yes {0} - run: | - using Pkg - Pkg.test("EnzymeCore"; coverage=true) - - uses: julia-actions/julia-processcoverage@v1 - if: matrix.version != 'nightly' || steps.run_tests.outcome == 'success' - with: - directories: lib/EnzymeCore/src - - uses: codecov/codecov-action@v7 - if: matrix.version != 'nightly' || steps.run_tests.outcome == 'success' - with: - files: lcov.info - token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: false # or true if you want CI to fail when Codecov fails diff --git a/src/utils.jl b/src/utils.jl index bb12d3dc5d..933d6ce3d2 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -8,8 +8,11 @@ function unsafe_to_pointer end export unsafe_to_pointer +const compiler_roots = Dict{Ptr{Cvoid}, Any}() +const compiler_roots_lock = ReentrantLock() + if VERSION >= v"1.12-" - @inline function unsafe_to_pointer(@nospecialize(val::Type)) + @inline function _unsafe_to_pointer(@nospecialize(val::Type)) return Core.Intrinsics.llvmcall(( """ declare nonnull ptr @julia.pointer_from_objref(ptr addrspace(11)) @@ -22,7 +25,7 @@ if VERSION >= v"1.12-" """, "f"), Ptr{Cvoid}, Tuple{Any}, val) end elseif Int == Int64 - @inline function unsafe_to_pointer(@nospecialize(val::Type)) + @inline function _unsafe_to_pointer(@nospecialize(val::Type)) return Base.llvmcall(( """ declare nonnull {}* @julia.pointer_from_objref({} addrspace(11)*) @@ -36,7 +39,7 @@ elseif Int == Int64 """, "f"), Ptr{Cvoid}, Tuple{Any}, val) end else - @inline function unsafe_to_pointer(@nospecialize(val::Type)) + @inline function _unsafe_to_pointer(@nospecialize(val::Type)) return Base.llvmcall(( """ declare nonnull {}* @julia.pointer_from_objref({} addrspace(11)*) @@ -51,6 +54,14 @@ else end end +function unsafe_to_pointer(@nospecialize(val::Type)) + ptr = _unsafe_to_pointer(val) + lock(compiler_roots_lock) do + compiler_roots[ptr] = val + end + return ptr +end + @inline is_concrete_tuple(x::Type{T2}) where {T2} = (T2 <: Tuple) && !(T2 === Tuple) && !(T2 isa UnionAll) diff --git a/test/runtests.jl b/test/runtests.jl index 31dcf8b65b..10920de6b7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,42 +1,18 @@ -import Enzyme -import Enzyme_jll -using ParallelTestRunner: addworker, filter_tests!, find_tests, parse_args, runtests +using Enzyme +using Test -# Start with autodiscovered tests -testsuite = find_tests(@__DIR__) -# Add threads tests to be run with multiple Julia threads (will be configured in -# `test_worker`). -testsuite["threads/2"] = :(include($(joinpath(@__DIR__, "threads.jl")))) -# Exclude integration tests, they're handled differently (they each run in their -# own environment) -for (k, _) in testsuite - startswith(k, "integration/") && delete!(testsuite, k) -end - -# Parse arguments -args = parse_args(ARGS) - -if filter_tests!(testsuite, args) - # Skip GPU-specific tests by default. - delete!(testsuite, "metal") - delete!(testsuite, "cuda") - delete!(testsuite, "amdgpu") - delete!(testsuite, "common") +Enzyme.API.printall!(true) +Enzyme.Compiler.DumpPostOpt[] = true - # Skipped until https://github.com/EnzymeAD/Enzyme.jl/issues/2620 is fixed. - if Sys.iswindows() - delete!(testsuite, "ext/specialfunctions") - end -end +@testset "BigFloat arithmetic" begin + a = BigFloat(1.234) + da = BigFloat(-0.23) + b = BigFloat(0.56) + db = BigFloat(0.27) + af64 = 1.234 # for testing mixed methods + daf64 = -0.23 # for testing mixed methods + bf64 = 0.56 # for testing mixed methods + dbf64 = 0.27 # for testing mixed methods -function test_worker(name) - if name == "threads/2" - # Run the `threads/2` testset, with multiple threads. - return addworker(; exeflags = ["--threads=2"]) - end + @test autodiff(Enzyme.Forward, +, Duplicated, Duplicated(a, da), Duplicated(b, db))[:1] ≈ da+db end - -const init_code = quote end - -@info "Testing against" Enzyme_jll.libEnzyme -runtests(Enzyme, args; testsuite, init_code, test_worker) diff --git a/test/test_isolated.jl b/test/test_isolated.jl new file mode 100644 index 0000000000..571c02b927 --- /dev/null +++ b/test/test_isolated.jl @@ -0,0 +1,47 @@ +using Enzyme, LinearAlgebra, Test + +function run_test() + T = UpperTriangular + TE = ComplexF64 + sizeB = (3,) + n = sizeB[1] + M = rand(TE, n, n) + B = rand(TE, sizeB...) + Y = zeros(TE, sizeB...) + A = T(M) + _A = T(A) + f!(Y, A, B, ::T) where {T} = ldiv!(Y, T(A), B) + + dY = (zeros(TE, sizeB...), zeros(TE, sizeB...)) + dM = (zeros(TE, n, n), zeros(TE, n, n)) + + activities = ( + Const(f!), + BatchDuplicated(Y, dY), + BatchDuplicated(M, dM), + Const(B), + Const(_A) + ) + + forward, reverse = autodiff_thunk( + ReverseSplitWithPrimal, + Const{typeof(f!)}, + BatchDuplicated, # return activity + map(typeof, Base.tail(activities))... # argument activities + ) + + println("Running targeted thunk forward...") + tape, y_ad, shadow_result = forward(Const(f!), Base.tail(activities)...) + + ȳ = (ones(TE, sizeB...), ones(TE, sizeB...)) + for (sr, dy) in zip(shadow_result, ȳ) + copyto!(sr, dy) + end + + println("Running targeted thunk reverse...") + reverse(Const(f!), Base.tail(activities)..., tape) +end + +@testset "Isolated custom test" begin + run_test() +end