Skip to content

Commit

Permalink
Fix type instability (#32)
Browse files Browse the repository at this point in the history
* fix type instability for large array ranks

* update ci and version

* change convert for less invalidations?
  • Loading branch information
Jutho authored Oct 26, 2024
1 parent 39bc28c commit dee352a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 46 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/CI-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ name: CI (Julia nightly)
on:
push:
branches:
- main
- workflow_dispatch
tags: ['*']
- 'master'
- 'main'
- 'release-'
tags: '*'
pull_request:
workflow_dispatch:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
Expand All @@ -28,7 +30,7 @@ jobs:
- x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
Expand All @@ -38,7 +40,7 @@ jobs:
env:
JULIA_NUM_THREADS: 4
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info

39 changes: 16 additions & 23 deletions .github/workflows/Invalidations.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
name: Invalidations

on:
pull_request:

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: always.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on: pull_request

jobs:
evaluate:
# Only run on PRs to the default branch.
# In the PR trigger above branches can be specified only explicitly whereas this check should work for master, main, or any other default branch
if: github.base_ref == github.event.repository.default_branch
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: '1'
version: 'lts'
- uses: actions/checkout@v4
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-invalidations@v1
id: invs_pr

- uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
- uses: julia-actions/julia-buildpkg@v1
ref: 'main'
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-invalidations@v1
id: invs_default
id: invs_main

- name: Report invalidation counts
run: |
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
- name: Check if the PR does increase number of invalidations
if: steps.invs_pr.outputs.total > steps.invs_default.outputs.total
run: exit 1
echo "Invalidations on main: ${{ steps.invs_main.outputs.total }} (${{ steps.invs_main.outputs.deps }} via deps)"
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)"
shell: bash
- name: PR doesn't increase number of invalidations
run: |
if (( ${{ steps.invs_pr.outputs.total }} > ${{ steps.invs_main.outputs.total }} )); then
exit 1
fi
shell: bash
17 changes: 10 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ name: CI
on:
push:
branches:
- main
- workflow_dispatch
tags: ['*']
- 'master'
- 'main'
- 'release-'
tags: '*'
pull_request:
workflow_dispatch:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
Expand All @@ -19,8 +21,9 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1'
- '1.6' # previous LTS release
- 'lts' # current LTS release
- '1' # current stable release
os:
- ubuntu-latest
- macOS-latest
Expand All @@ -29,7 +32,7 @@ jobs:
- x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
Expand All @@ -39,7 +42,7 @@ jobs:
env:
JULIA_NUM_THREADS: 4
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info

6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Strided"
uuid = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
authors = ["Lukas Devos <[email protected]>", "Maarten Van Damme <[email protected]>", "Jutho Haegeman <[email protected]>"]
version = "2.1.1"
version = "2.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -12,9 +12,9 @@ TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
Aqua = "0.8"
LinearAlgebra = "1.6"
Random = "1.6"
StridedViews = "0.1,0.2,0.3"
StridedViews = "0.3.2"
Test = "1.6"
TupleTools = "1.1"
TupleTools = "1.6"
julia = "1.6"

[extras]
Expand Down
13 changes: 10 additions & 3 deletions src/convert.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
function Base.convert(::Type{T}, a::StridedView) where {T<:Array}
b = T(undef, size(a))
function Base.Array(a::StridedView)
b = Array{eltype(a)}(undef, size(a))
copyto!(StridedView(b), a)
return b
end
function Base.convert(::Type{Array}, a::StridedView{T}) where {T}

function (Base.Array{T})(a::StridedView{S,N}) where {T,S,N}
b = Array{T}(undef, size(a))
copyto!(StridedView(b), a)
return b
end

function (Base.Array{T,N})(a::StridedView{S,N}) where {T,S,N}
b = Array{T}(undef, size(a))
copyto!(StridedView(b), a)
return b
Expand Down
10 changes: 5 additions & 5 deletions src/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ function _mapreduce(f, op, A::StridedView{T}, nt=nothing) where {T}
return out[ParentIndex(1)]
end

@inline function Base.mapreducedim!(f, op, b::StridedView{<:Any,N},
a1::StridedView{<:Any,N},
A::Vararg{StridedView{<:Any,N}}) where {N}
function Base.mapreducedim!(f, op, b::StridedView{<:Any,N},
a1::StridedView{<:Any,N},
A::Vararg{StridedView{<:Any,N}}) where {N}
outdims = size(b)
dims = map(max, outdims, map(max, map(size, (a1, A...))...))

Expand Down Expand Up @@ -176,7 +176,7 @@ function _mapreduce_block!((f), (op), (initop),
_mapreduce_threaded!(f, op, initop, dims, blocks, strides, offsets, costs, arrays,
get_num_threads(), 0, 1)
end
return
return nothing
end

_init_reduction!(out, f, op::Union{typeof(+),typeof(Base.add_sum)}, a) = fill!(out, zero(a))
Expand Down Expand Up @@ -483,7 +483,7 @@ function _computeblocks(dims::NTuple{N,Int}, costs::NTuple{N,Int},
end

if minimum(minimum.(bytestrides)) > blocksize
return ntuple(n -> 1, N)
return ntuple(n -> 1, Val(N))
end

# reduce dims to find appropriate blocks
Expand Down

2 comments on commit dee352a

@Jutho
Copy link
Owner Author

@Jutho Jutho commented on dee352a Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes

  • (re)export isstrided (from StridedViews.jl)
  • fix type instability for large tuples / arrays with large ranks
  • remove invalidations

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/118127

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.2.0 -m "<description of version>" dee352aa8c5aa5ce124657bed9c2783220dc2623
git push origin v2.2.0

Please sign in to comment.