From 71cb979ada642548169d16bd9a1e00776eebcff0 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Thu, 2 Jan 2025 18:38:18 +0800 Subject: [PATCH 1/9] atomics: update llvmcall for `load,store,cmpxchg` --- src/atomics.jl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/atomics.jl b/src/atomics.jl index 462366c..8e9e88b 100644 --- a/src/atomics.jl +++ b/src/atomics.jl @@ -1,23 +1,21 @@ + for (ityp,jtyp) ∈ [("i8", UInt8), ("i16", UInt16), ("i32", UInt32), ("i64", UInt64), ("i128", UInt128)] @eval begin @inline function _atomic_load(ptr::Ptr{$jtyp}) Base.llvmcall($(""" - %p = inttoptr i$(8sizeof(Int)) %0 to $(ityp)* - %v = load atomic $(ityp), $(ityp)* %p acquire, align $(Base.gc_alignment(jtyp)) + %v = load atomic $(ityp), ptr %0 acquire, align $(Base.gc_alignment(jtyp)) ret $(ityp) %v """), $jtyp, Tuple{Ptr{$jtyp}}, ptr) end @inline function _atomic_store!(ptr::Ptr{$jtyp}, x::$jtyp) Base.llvmcall($(""" - %p = inttoptr i$(8sizeof(Int)) %0 to $(ityp)* - store atomic $(ityp) %1, $(ityp)* %p release, align $(Base.gc_alignment(jtyp)) + store atomic $(ityp) %1, ptr %0 release, align $(Base.gc_alignment(jtyp)) ret void """), Cvoid, Tuple{Ptr{$jtyp}, $jtyp}, ptr, x) end @inline function _atomic_cas_cmp!(ptr::Ptr{$jtyp}, cmp::$jtyp, newval::$jtyp) Base.llvmcall($(""" - %p = inttoptr i$(8sizeof(Int)) %0 to $(ityp)* - %c = cmpxchg $(ityp)* %p, $(ityp) %1, $(ityp) %2 acq_rel acquire + %c = cmpxchg ptr %0, $(ityp) %1, $(ityp) %2 acq_rel acquire %bit = extractvalue { $ityp, i1 } %c, 1 %bool = zext i1 %bit to i8 ret i8 %bool From e4aa0d1717630a45af60f83536eb5c39367bdcbf Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Thu, 2 Jan 2025 18:38:54 +0800 Subject: [PATCH 2/9] atomics: update llvmcall for `atomicrmw_ops` --- src/atomics.jl | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/atomics.jl b/src/atomics.jl index 8e9e88b..e57bca7 100644 --- a/src/atomics.jl +++ b/src/atomics.jl @@ -23,14 +23,28 @@ for (ityp,jtyp) ∈ [("i8", UInt8), ("i16", UInt16), ("i32", UInt32), ("i64", UI end end end -for op ∈ ["xchg", "add", "sub", "and", "nand", "or", "xor", "max", "min", "umax", "umin"] # "fadd", "fsub" + +""" +Operations supported by `atomicrmw`. + +- Julia v1.11 use [libLLVM-16](https://releases.llvm.org/16.0.0/docs/LangRef.html#atomicrmw-instruction) +""" +const atomicrmw_ops = [ + "xchg", "add", "sub", + "and", "nand", "or", "xor", + "max", "min", "umax", "umin", + # "fadd", "fsub", + # "fmax", "fmin", + # "uinc_wrap", "udec_wrap", # Need LLVM 16: VERSION >= v"1.11" +] +for op ∈ atomicrmw_ops f = Symbol("_atomic_", op, '!') for (ityp,jtyp) ∈ [("i8", UInt8), ("i16", UInt16), ("i32", UInt32), ("i64", UInt64), ("i128", UInt128)] @eval begin + # Do inplace `$(op)` for `*ptr` and `x` atomically, return the old value of `*ptr`. @inline function $f(ptr::Ptr{$jtyp}, x::$jtyp) Base.llvmcall($(""" - %p = inttoptr i$(8sizeof(Int)) %0 to $(ityp)* - %v = atomicrmw $op $(ityp)* %p, $(ityp) %1 acq_rel + %v = atomicrmw $(op) ptr %0, $(ityp) %1 acq_rel ret $(ityp) %v """), $jtyp, Tuple{Ptr{$jtyp}, $jtyp}, ptr, x) end @@ -42,9 +56,9 @@ for op ∈ ["xchg", "add", "sub", "and", "nand", "or", "xor", "max", "min", "uma end end end + @inline _atomic_state(ptr::Ptr{UInt}) = reinterpret(ThreadState, _atomic_load(reinterpret(Ptr{UInt32}, ptr))) @inline _atomic_store!(ptr::Ptr{UInt}, x::ThreadState) = _atomic_store!(reinterpret(Ptr{UInt32}, ptr), reinterpret(UInt32, x)) @inline function _atomic_cas_cmp!(ptr::Ptr{UInt}, cmp::ThreadState, newval::ThreadState) _atomic_cas_cmp!(reinterpret(Ptr{UInt32}, ptr), reinterpret(UInt32, cmp), reinterpret(UInt32, newval)) end - From 6ad1ecda969df6c20d765492cb043569634721a2 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Thu, 2 Jan 2025 18:44:15 +0800 Subject: [PATCH 3/9] compat: need julia 1.11+ --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f378f6f..b00ffae 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,7 @@ ManualMemory = "d125e4d3-2237-4719-b19c-fa641b8a4667" [compat] Aqua = "0.5" ManualMemory = "0.1.1" -julia = "1.5" +julia = "1.11" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" From d3cb03e118a84674744808e97c4a3d91560f3ac0 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Thu, 2 Jan 2025 23:01:27 +0800 Subject: [PATCH 4/9] ci: update github actions --- .github/workflows/ci-julia-nightly.yml | 35 ++++++++------------------ .github/workflows/ci.yml | 34 +++++++++++-------------- 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci-julia-nightly.yml b/.github/workflows/ci-julia-nightly.yml index b8e67fc..1256b81 100644 --- a/.github/workflows/ci-julia-nightly.yml +++ b/.github/workflows/ci-julia-nightly.yml @@ -18,51 +18,36 @@ on: jobs: test-julia-nightly: timeout-minutes: 30 - name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - arch: - - x64 - - x86 + # use default arch exclusive: - '0' os: - ubuntu-latest - - macOS-latest + - macOS-latest # arm - windows-latest threads: - '5' version: - - '1.5' - - '1' + # Runs on Julia nightly only. - 'nightly' - exclude: - - os: macOS-latest - arch: x86 # 32-bit Julia binaries are not available on macOS include: - - exclusive: '1' - threads: '2' - arch: x64 + # (exclusive=1, threads=2) + - arch: x64 + exclusive: '1' os: ubuntu-latest - version: '1' + threads: '2' + version: '1.11' steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} - arch: ${{ matrix.arch }} - - uses: actions/cache@v4 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- + - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 env: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0ad3c0..8477edd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,39 +30,35 @@ jobs: - '0' os: - ubuntu-latest - - macOS-latest - windows-latest + - macos-13 # Intel threads: - '5' version: - - '1.5' - - '1' - - 'nightly' + - '1.11' + # - '1' # Use this when julia +1 > 1.11 exclude: - - os: macOS-latest + - os: macos-13 arch: x86 # 32-bit Julia binaries are not available on macOS include: - - exclusive: '1' - threads: '2' - arch: x64 + - arch: aarch64 + exclusive: '0' + os: macOS-latest # Arm + threads: '5' + version: '1.11' + # (exclusive=1, threads=2) + - arch: x64 + exclusive: '1' os: ubuntu-latest - version: '1' + threads: '2' + version: '1.11' steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: actions/cache@v4 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- + - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 env: From 03021ba95906f1bad0a7ff2fca89d1132be69613 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 16:25:46 +0800 Subject: [PATCH 5/9] Revert "compat: need julia 1.11+" This reverts commit 6ad1ecda969df6c20d765492cb043569634721a2. --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index b00ffae..f378f6f 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,7 @@ ManualMemory = "d125e4d3-2237-4719-b19c-fa641b8a4667" [compat] Aqua = "0.5" ManualMemory = "0.1.1" -julia = "1.11" +julia = "1.5" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" From 349c2a589ca30923b0b7f5f1d8f5e86b343ba446 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 16:40:31 +0800 Subject: [PATCH 6/9] atomics: fix compat with julia <= v1.11 --- src/atomics.jl | 79 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/src/atomics.jl b/src/atomics.jl index e57bca7..7d44d6a 100644 --- a/src/atomics.jl +++ b/src/atomics.jl @@ -2,24 +2,57 @@ for (ityp,jtyp) ∈ [("i8", UInt8), ("i16", UInt16), ("i32", UInt32), ("i64", UInt64), ("i128", UInt128)] @eval begin @inline function _atomic_load(ptr::Ptr{$jtyp}) - Base.llvmcall($(""" - %v = load atomic $(ityp), ptr %0 acquire, align $(Base.gc_alignment(jtyp)) - ret $(ityp) %v - """), $jtyp, Tuple{Ptr{$jtyp}}, ptr) + Base.llvmcall($( + @static if VERSION >= v"1.12-DEV" + # use opaque pointers #53 + """ + %v = load atomic $(ityp), ptr %0 acquire, align $(Base.gc_alignment(jtyp)) + ret $(ityp) %v + """ + else + """ + %p = inttoptr i$(8sizeof(Int)) %0 to $(ityp)* + %v = load atomic $(ityp), $(ityp)* %p acquire, align $(Base.gc_alignment(jtyp)) + ret $(ityp) %v + """ + end + ), $jtyp, Tuple{Ptr{$jtyp}}, ptr) end @inline function _atomic_store!(ptr::Ptr{$jtyp}, x::$jtyp) - Base.llvmcall($(""" - store atomic $(ityp) %1, ptr %0 release, align $(Base.gc_alignment(jtyp)) - ret void - """), Cvoid, Tuple{Ptr{$jtyp}, $jtyp}, ptr, x) + Base.llvmcall($( + @static if VERSION >= v"1.12-DEV" + """ + store atomic $(ityp) %1, ptr %0 release, align $(Base.gc_alignment(jtyp)) + ret void + """ + else + """ + %p = inttoptr i$(8sizeof(Int)) %0 to $(ityp)* + store atomic $(ityp) %1, $(ityp)* %p release, align $(Base.gc_alignment(jtyp)) + ret void + """ + end + ), Cvoid, Tuple{Ptr{$jtyp}, $jtyp}, ptr, x) end @inline function _atomic_cas_cmp!(ptr::Ptr{$jtyp}, cmp::$jtyp, newval::$jtyp) - Base.llvmcall($(""" - %c = cmpxchg ptr %0, $(ityp) %1, $(ityp) %2 acq_rel acquire - %bit = extractvalue { $ityp, i1 } %c, 1 - %bool = zext i1 %bit to i8 - ret i8 %bool - """), Bool, Tuple{Ptr{$jtyp}, $jtyp, $jtyp}, ptr, cmp, newval) + Base.llvmcall($( + @static if VERSION >= v"1.12-DEV" + """ + %c = cmpxchg ptr %0, $(ityp) %1, $(ityp) %2 acq_rel acquire + %bit = extractvalue { $ityp, i1 } %c, 1 + %bool = zext i1 %bit to i8 + ret i8 %bool + """ + else + """ + %p = inttoptr i$(8sizeof(Int)) %0 to $(ityp)* + %c = cmpxchg $(ityp)* %p, $(ityp) %1, $(ityp) %2 acq_rel acquire + %bit = extractvalue { $ityp, i1 } %c, 1 + %bool = zext i1 %bit to i8 + ret i8 %bool + """ + end + ), Bool, Tuple{Ptr{$jtyp}, $jtyp, $jtyp}, ptr, cmp, newval) end end end @@ -43,10 +76,20 @@ for op ∈ atomicrmw_ops @eval begin # Do inplace `$(op)` for `*ptr` and `x` atomically, return the old value of `*ptr`. @inline function $f(ptr::Ptr{$jtyp}, x::$jtyp) - Base.llvmcall($(""" - %v = atomicrmw $(op) ptr %0, $(ityp) %1 acq_rel - ret $(ityp) %v - """), $jtyp, Tuple{Ptr{$jtyp}, $jtyp}, ptr, x) + Base.llvmcall($( + @static if VERSION >= v"1.12-DEV" + """ + %v = atomicrmw $(op) ptr %0, $(ityp) %1 acq_rel + ret $(ityp) %v + """ + else + """ + %p = inttoptr i$(8sizeof(Int)) %0 to $(ityp)* + %v = atomicrmw $op $(ityp)* %p, $(ityp) %1 acq_rel + ret $(ityp) %v + """ + end + ), $jtyp, Tuple{Ptr{$jtyp}, $jtyp}, ptr, x) end end end From 6b483272ca31eefba515a1df89738834cff72a0e Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 16:56:25 +0800 Subject: [PATCH 7/9] ci: test with v1.5 --- .github/workflows/ci-julia-nightly.yml | 2 +- .github/workflows/ci.yml | 29 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-julia-nightly.yml b/.github/workflows/ci-julia-nightly.yml index 1256b81..4015fba 100644 --- a/.github/workflows/ci-julia-nightly.yml +++ b/.github/workflows/ci-julia-nightly.yml @@ -41,7 +41,7 @@ jobs: exclusive: '1' os: ubuntu-latest threads: '2' - version: '1.11' + version: 'nightly' steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8477edd..7377920 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,32 +26,43 @@ jobs: arch: - x64 - x86 + - aarch64 exclusive: - '0' os: - ubuntu-latest - windows-latest - - macos-13 # Intel + - macos-latest # Arm threads: - '5' version: - - '1.11' - # - '1' # Use this when julia +1 > 1.11 + - '1.5' + - '1' exclude: - - os: macos-13 - arch: x86 # 32-bit Julia binaries are not available on macOS + - os: ubuntu-latest + arch: aarch64 + - os: windows-latest + arch: aarch64 include: - - arch: aarch64 + # 32-bit Julia binaries are not available on macOS (Intel) + # (macos-13, x64, v"1.5") + - arch: x64 + exclusive: '0' + os: macos-13 # Intel + threads: '5' + version: '1.5' + # (macos-13, x64, v"1") + - arch: x64 exclusive: '0' - os: macOS-latest # Arm + os: macos-13 # Intel threads: '5' - version: '1.11' + version: '1' # (exclusive=1, threads=2) - arch: x64 exclusive: '1' os: ubuntu-latest threads: '2' - version: '1.11' + version: '1' steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 From 22c3298515a7c521663badb35d9963b2c111d86a Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 17:08:12 +0800 Subject: [PATCH 8/9] ci: macos-latest need julia v1.8+ --- .github/workflows/ci.yml | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7377920..550857b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,37 +26,26 @@ jobs: arch: - x64 - x86 - - aarch64 exclusive: - '0' os: - ubuntu-latest - windows-latest - - macos-latest # Arm + - macos-13 # Intel threads: - '5' version: - '1.5' - '1' exclude: - - os: ubuntu-latest - arch: aarch64 - - os: windows-latest - arch: aarch64 + - os: macos-13 + arch: x86 # 32-bit Julia binaries are not available on macOS include: - # 32-bit Julia binaries are not available on macOS (Intel) - # (macos-13, x64, v"1.5") - - arch: x64 + - arch: aarch64 exclusive: '0' - os: macos-13 # Intel + os: macos-latest # Arm threads: '5' - version: '1.5' - # (macos-13, x64, v"1") - - arch: x64 - exclusive: '0' - os: macos-13 # Intel - threads: '5' - version: '1' + version: '1' # macos-latest (aarch64) need Julia >= v1.8+ # (exclusive=1, threads=2) - arch: x64 exclusive: '1' From 305909d8f5c225759ed9de8f9d2f4ecd3b8602db Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 17:13:48 +0800 Subject: [PATCH 9/9] ci: Update codecov-action --- .github/workflows/ci-julia-nightly.yml | 4 ++-- .github/workflows/ci.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-julia-nightly.yml b/.github/workflows/ci-julia-nightly.yml index 4015fba..7aaccae 100644 --- a/.github/workflows/ci-julia-nightly.yml +++ b/.github/workflows/ci-julia-nightly.yml @@ -54,6 +54,6 @@ jobs: JULIA_EXCLUSIVE: ${{ matrix.exclusive }} JULIA_NUM_THREADS: ${{ matrix.threads }} - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v5 with: - file: lcov.info + files: lcov.info diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 550857b..c2ca055 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,9 +65,9 @@ jobs: JULIA_EXCLUSIVE: ${{ matrix.exclusive }} JULIA_NUM_THREADS: ${{ matrix.threads }} - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v5 with: - file: lcov.info + files: lcov.info docs: name: Documentation runs-on: ubuntu-latest