Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jaeyeon/newdispatch #362

Closed
wants to merge 8 commits into from
Closed
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
84 changes: 16 additions & 68 deletions docs/src/interactive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,26 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"An example generating sparse code with Finch, make some changes and give it a try!\n",
"\n",
"A note to visitors using Binder: it may take a minute or\n",
"two to compile the first kernel, perhaps enjoy a nice little coffee break ^.^"
]
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"quote\n",
" y = ex.body.body.lhs.tns.bind\n",
" A_lvl = (ex.body.body.rhs.args[1]).tns.bind.lvl\n",
" A_lvl_2 = A_lvl.lvl\n",
" A_lvl_ptr = A_lvl_2.ptr\n",
" A_lvl_idx = A_lvl_2.idx\n",
" A_lvl_2_val = A_lvl_2.lvl.val\n",
" x = (ex.body.body.rhs.args[2]).tns.bind\n",
" sugar_1 = size(y)\n",
" y_mode1_stop = sugar_1[1]\n",
" A_lvl_2.shape == y_mode1_stop || throw(DimensionMismatch(\"mismatched dimension limits ($(A_lvl_2.shape) != $(y_mode1_stop))\"))\n",
" sugar_2 = size(x)\n",
" x_mode1_stop = sugar_2[1]\n",
" x_mode1_stop == A_lvl.shape || throw(DimensionMismatch(\"mismatched dimension limits ($(x_mode1_stop) != $(A_lvl.shape))\"))\n",
" for j_4 = 1:x_mode1_stop\n",
" sugar_3 = size(x)\n",
" x_mode1_stop = sugar_3[1]\n",
" val = x[j_4]\n",
" A_lvl_q = (1 - 1) * A_lvl.shape + j_4\n",
" A_lvl_2_q = A_lvl_ptr[A_lvl_q]\n",
" A_lvl_2_q_stop = A_lvl_ptr[A_lvl_q + 1]\n",
" if A_lvl_2_q < A_lvl_2_q_stop\n",
" A_lvl_2_i1 = A_lvl_idx[A_lvl_2_q_stop - 1]\n",
" else\n",
" A_lvl_2_i1 = 0\n",
" end\n",
" phase_stop = min(A_lvl_2.shape, A_lvl_2_i1)\n",
" if phase_stop >= 1\n",
" if A_lvl_idx[A_lvl_2_q] < 1\n",
" A_lvl_2_q = Finch.scansearch(A_lvl_idx, 1, A_lvl_2_q, A_lvl_2_q_stop - 1)\n",
" end\n",
" while true\n",
" A_lvl_2_i = A_lvl_idx[A_lvl_2_q]\n",
" if A_lvl_2_i < phase_stop\n",
" A_lvl_3_val = A_lvl_2_val[A_lvl_2_q]\n",
" y[A_lvl_2_i] = val * A_lvl_3_val + y[A_lvl_2_i]\n",
" A_lvl_2_q += 1\n",
" else\n",
" phase_stop_3 = min(A_lvl_2_i, phase_stop)\n",
" if A_lvl_2_i == phase_stop_3\n",
" A_lvl_3_val = A_lvl_2_val[A_lvl_2_q]\n",
" y[phase_stop_3] = val * A_lvl_3_val + y[phase_stop_3]\n",
" A_lvl_2_q += 1\n",
" end\n",
" break\n",
" end\n",
" end\n",
" end\n",
" end\n",
" (y = y,)\n",
"end"
]
"text/plain": "quote\n y = ex.body.body.lhs.tns.bind\n A_lvl = (ex.body.body.rhs.args[1]).tns.bind.lvl\n A_lvl_2 = A_lvl.lvl\n A_lvl_ptr = A_lvl_2.ptr\n A_lvl_idx = A_lvl_2.idx\n A_lvl_2_val = A_lvl_2.lvl.val\n x = (ex.body.body.rhs.args[2]).tns.bind\n sugar_1 = size(y)\n y_mode1_stop = sugar_1[1]\n A_lvl_2.shape == y_mode1_stop || throw(DimensionMismatch(\"mismatched dimension limits ($(A_lvl_2.shape) != $(y_mode1_stop))\"))\n sugar_2 = size(x)\n x_mode1_stop = sugar_2[1]\n x_mode1_stop == A_lvl.shape || throw(DimensionMismatch(\"mismatched dimension limits ($(x_mode1_stop) != $(A_lvl.shape))\"))\n for j_4 = 1:x_mode1_stop\n sugar_3 = size(x)\n x_mode1_stop = sugar_3[1]\n val = x[j_4]\n A_lvl_q = (1 - 1) * A_lvl.shape + j_4\n A_lvl_2_q = A_lvl_ptr[A_lvl_q]\n A_lvl_2_q_stop = A_lvl_ptr[A_lvl_q + 1]\n if A_lvl_2_q < A_lvl_2_q_stop\n A_lvl_2_i1 = A_lvl_idx[A_lvl_2_q_stop - 1]\n else\n A_lvl_2_i1 = 0\n end\n phase_stop = min(A_lvl_2.shape, A_lvl_2_i1)\n if phase_stop >= 1\n if A_lvl_idx[A_lvl_2_q] < 1\n A_lvl_2_q = Finch.scansearch(A_lvl_idx, 1, A_lvl_2_q, A_lvl_2_q_stop - 1)\n end\n while true\n A_lvl_2_i = A_lvl_idx[A_lvl_2_q]\n if A_lvl_2_i < phase_stop\n A_lvl_3_val = A_lvl_2_val[A_lvl_2_q]\n y[A_lvl_2_i] = val * A_lvl_3_val + y[A_lvl_2_i]\n A_lvl_2_q += 1\n else\n phase_stop_3 = min(phase_stop, A_lvl_2_i)\n if A_lvl_2_i == phase_stop_3\n A_lvl_3_val = A_lvl_2_val[A_lvl_2_q]\n y[phase_stop_3] = val * A_lvl_3_val + y[phase_stop_3]\n A_lvl_2_q += 1\n end\n break\n end\n end\n end\n end\n (y = y,)\nend"
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
"execution_count": 1
}
],
"cell_type": "code",
"source": [
"using Finch\n",
"\n",
Expand All @@ -92,22 +38,24 @@
" y[i] += A[i, j] * x[j]\n",
" end\n",
"end"
]
],
"metadata": {},
"execution_count": 1
}
],
"nbformat_minor": 3,
"metadata": {
"kernelspec": {
"display_name": "Julia 1.6.7",
"language": "julia",
"name": "julia-1.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.6.7"
},
"kernelspec": {
"name": "julia-1.6",
"display_name": "Julia 1.6.7",
"language": "julia"
}
},
"nbformat": 4,
"nbformat_minor": 3
"nbformat": 4
}
2 changes: 1 addition & 1 deletion docs/src/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ quote
s_val = A_lvl_2_val + s_val
A_lvl_q += 1
else
phase_stop_3 = min(A_lvl_i, phase_stop)
phase_stop_3 = min(phase_stop, A_lvl_i)
if A_lvl_i == phase_stop_3
A_lvl_2_val = A_lvl_val[A_lvl_q]
s_val = s_val + A_lvl_2_val
Expand Down
12 changes: 6 additions & 6 deletions docs/src/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ quote
s_val = A_lvl_3_val + s_val
A_lvl_2_q += 1
else
phase_stop_3 = min(A_lvl_2_i, phase_stop)
phase_stop_3 = min(phase_stop, A_lvl_2_i)
if A_lvl_2_i == phase_stop_3
A_lvl_3_val = A_lvl_2_val[A_lvl_2_q]
s_val = s_val + A_lvl_3_val
Expand Down Expand Up @@ -127,7 +127,7 @@ quote
s_val = A_lvl_3_val + s_val
A_lvl_2_q += 1
else
phase_stop_3 = min(A_lvl_2_i, phase_stop)
phase_stop_3 = min(phase_stop, A_lvl_2_i)
if A_lvl_2_i == phase_stop_3
A_lvl_3_val = A_lvl_2_val[A_lvl_2_q]
s_val = s_val + A_lvl_3_val
Expand Down Expand Up @@ -278,7 +278,7 @@ quote
A_lvl_2_q += 1
i = A_lvl_2_i + 1
else
phase_stop_3 = min(A_lvl_2_i, phase_stop)
phase_stop_3 = min(phase_stop, A_lvl_2_i)
if A_lvl_2_i == phase_stop_3
for i_8 = i:phase_stop_3 - 1
val = B[i_8, j_4]
Expand All @@ -305,9 +305,9 @@ quote
end
end
end
phase_start_3 = max(1, 1 + A_lvl_2_i1)
if B_mode1_stop >= phase_start_3
for i_12 = phase_start_3:B_mode1_stop
phase_start = max(1, 1 + A_lvl_2_i1)
if B_mode1_stop >= phase_start
for i_12 = phase_start:B_mode1_stop
sugar_8 = size(B)
B_mode1_stop = sugar_8[1]
B_mode2_stop = sugar_8[2]
Expand Down
16 changes: 8 additions & 8 deletions src/dimensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@

function virtual_intersect(ctx, a::Extent, b::Extent)
Extent(
start = @f(max($(getstart(a)), $(getstart(b)))),
stop = @f(min($(getstop(a)), $(getstop(b))))
start = simplify(@f(max($(getstart(a)), $(getstart(b)))), ctx),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I used to do it this way, but all the extra calls to simplify slowed the compiler down, so we avoid this now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The CI tests on the main branch used to fail because the result of simplify was occasionally different on x64 Ubuntu Julia 1.6.7 when the Finch expression included a Limit.

Therefore, I attempted to explicitly launch the simplify pass using this code snippet to verify if it works. In any case, it appears that your main branch now passes the continuous tests after your hash fix, so I assume the underlying issue was related to the static hash handling of the Limit type. Consequently, we can remove this change.

stop = simplify(@f(min($(getstop(a)), $(getstop(b)))), ctx)
)
end

Expand All @@ -244,8 +244,8 @@
#virtual_union(ctx, a, b) = virtual_union(ctx, promote(a, b)...)
function virtual_union(ctx, a::Extent, b::Extent)
Extent(
start = @f(min($(getstart(a)), $(getstart(b)))),
stop = @f(max($(getstop(a)), $(getstop(b))))
start = simplify(@f(min($(getstart(a)), $(getstart(b)))), ctx),
stop = simplify(@f(max($(getstop(a)), $(getstop(b)))), ctx)
)
end

Expand Down Expand Up @@ -299,14 +299,14 @@

function virtual_intersect(ctx, a::ContinuousExtent, b::ContinuousExtent)
ContinuousExtent(
start = @f(max($(getstart(a)), $(getstart(b)))),
stop = @f(min($(getstop(a)), $(getstop(b))))
start = simplify(@f(max($(getstart(a)), $(getstart(b)))), ctx),
stop = simplify(@f(min($(getstop(a)), $(getstop(b)))), ctx)
)
end

function virtual_union(ctx, a::ContinuousExtent, b::ContinuousExtent)
ContinuousExtent(
start = @f(min($(getstart(a)), $(getstart(b)))),
stop = @f(max($(getstop(a)), $(getstop(b))))
start = simplify(@f(min($(getstart(a)), $(getstart(b)))), ctx),
stop = simplify(@f(max($(getstop(a)), $(getstop(b)))), ctx)

Check warning on line 310 in src/dimensions.jl

View check run for this annotation

Codecov / codecov/patch

src/dimensions.jl#L309-L310

Added lines #L309 - L310 were not covered by tests
)
end
50 changes: 24 additions & 26 deletions src/util/limits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,30 @@
Base.:(-)(x::Limit)::Limit = limit(-x.val, -x.sign)

#Crazy julia multiple dispatch stuff don't worry about it
limit_types = [Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, BigInt, Float32, Float64]
for S in limit_types
Copy link
Collaborator

Choose a reason for hiding this comment

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

This for loop avoids method ambiguities on types that define e.g. max(a::MyType, b::Real). If we define max(a::Real, b::Limit) where Limit <: Real, then we get an ambiguity error. If we want to take your approach, we need to make Limit not be a subtype of Number. I understand that this is suboptimal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I see that currently Limit <: Number, so Limit is not currently subtyping Real. I think this might work then. But should we have Limit <: Real?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was also a random attempt to address the CI issues in continuous testing. While it makes the code cleaner, it introduces ambiguity. Since the CI now passes, I believe we no longer need this pull request. Let's close it.

@eval begin
@inline Base.promote_rule(::Type{Limit{T}}, ::Type{$S}) where {T} = Limit{promote_type(T, $S)}
Base.convert(::Type{Limit{T}}, i::$S) where {T} = limit(convert(T, i))
Limit(i::$S) = Limit{$S}(i, tiny_zero())
(::Type{$S})(i::Limit{T}) where {T} = convert($S, i.val)
Base.convert(::Type{$S}, i::Limit) = convert($S, i.val)
Base.:(+)(x::Limit, y::$S)::Limit = x + limit(y)
Base.:(+)(x::$S, y::Limit)::Limit = limit(x) + y
Base.:(-)(x::Limit, y::$S)::Limit = x - limit(y)
Base.:(-)(x::$S, y::Limit)::Limit = limit(x) - y
Base.:(<)(x::Limit, y::$S) = x < limit(y)
Base.:(<)(x::$S, y::Limit) = limit(x) < y
Base.:(<=)(x::Limit, y::$S) = x <= limit(y)
Base.:(<=)(x::$S, y::Limit) = limit(x) <= y
Base.:(==)(x::Limit, y::$S) = x == limit(y)
Base.:(==)(x::$S, y::Limit) = limit(x) == y
Base.isless(x::Limit, y::$S) = x < limit(y)
Base.isless(x::$S, y::Limit) = limit(x) < y
Base.max(x::$S, y::Limit)::Limit = max(limit(x), y)
Base.max(x::Limit, y::$S)::Limit = max(x, limit(y))
Base.min(x::$S, y::Limit)::Limit = min(limit(x), y)
Base.min(x::Limit, y::$S)::Limit = min(x, limit(y))
end
end
Base.promote_rule(::Type{Limit{T}}, ::Type{S}) where {T, S<:Real} = Limit{promote_type(T, S)}
Base.convert(::Type{Limit{T}}, i::Real) where {T} = limit(convert(T, i))
Limit(i::S) where {S<:Real} = Limit{S}(i, tiny_zero())
(::Type{S})(i::Limit{T}) where {T, S<:Real} = convert(S, i.val)
Base.convert(::Type{S}, i::Limit) where {S<:Real} = convert(S, i.val)

Check warning on line 173 in src/util/limits.jl

View check run for this annotation

Codecov / codecov/patch

src/util/limits.jl#L171-L173

Added lines #L171 - L173 were not covered by tests
Base.:(+)(x::Limit, y::Real)::Limit = x + limit(y)
Base.:(+)(x::Real, y::Limit)::Limit = limit(x) + y
Base.:(-)(x::Limit, y::Real)::Limit = x - limit(y)

Check warning on line 176 in src/util/limits.jl

View check run for this annotation

Codecov / codecov/patch

src/util/limits.jl#L176

Added line #L176 was not covered by tests
Base.:(-)(x::Real, y::Limit)::Limit = limit(x) - y
Base.:(<)(x::Limit, y::Real) = x < limit(y)

Check warning on line 178 in src/util/limits.jl

View check run for this annotation

Codecov / codecov/patch

src/util/limits.jl#L178

Added line #L178 was not covered by tests
Base.:(<)(x::Real, y::Limit) = limit(x) < y
Base.:(<=)(x::Limit, y::Real) = x <= limit(y)
Base.:(<=)(x::Real, y::Limit) = limit(x) <= y
Base.:(==)(x::Limit, y::Real) = x == limit(y)
Base.:(==)(x::Real, y::Limit) = limit(x) == y
Base.isless(x::Limit, y::Real) = x < limit(y)
Base.isless(x::Real, y::Limit) = limit(x) < y

Check warning on line 185 in src/util/limits.jl

View check run for this annotation

Codecov / codecov/patch

src/util/limits.jl#L184-L185

Added lines #L184 - L185 were not covered by tests
Base.max(x::Real, y::Limit)::Limit = max(limit(x), y)
Base.max(x::Limit, y::Real)::Limit = max(x, limit(y))
Base.min(x::Real, y::Limit)::Limit = min(limit(x), y)
Base.min(x::Limit, y::Real)::Limit = min(x, limit(y))




Base.promote_rule(::Type{Limit{T}}, ::Type{Limit{S}}) where {T, S} = Limit(promote_type(T, S))
Base.convert(::Type{Limit{T}}, i::Limit) where {T} = Limit{T}(convert(T, i.val), i.sign)
Expand Down
49 changes: 24 additions & 25 deletions test/reference32/concat_offset_permit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ begin
C_lvl_qos += 1
A_lvl_q += 1
else
phase_stop_5 = min(A_lvl_i, phase_stop_3)
phase_stop_5 = min(phase_stop_3, A_lvl_i)
if A_lvl_i == phase_stop_5
A_lvl_2_val = A_lvl_val[A_lvl_q]
if C_lvl_qos > C_lvl_qos_stop
Expand All @@ -79,10 +79,10 @@ begin
end
end
end
phase_start_6 = max(1, 1 + A_lvl.shape)
phase_start_2 = max(1, 1 + A_lvl.shape)
phase_stop_7 = min(C_lvl.shape, 10)
if phase_stop_7 >= phase_start_6
for i_14 = phase_start_6:phase_stop_7
if phase_stop_7 >= phase_start_2
for i_14 = phase_start_2:phase_stop_7
if C_lvl_qos > C_lvl_qos_stop
C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
Finch.resize_if_smaller!(C_lvl_idx, C_lvl_qos_stop)
Expand Down Expand Up @@ -204,11 +204,11 @@ begin
i = phase_stop_15 + 1
end
end
phase_start_16 = max(11 + B_lvl_i1, 11)
phase_start_6 = max(11, 11 + B_lvl_i1)
phase_stop_17 = min(A_lvl_i1, phase_stop_13)
if phase_stop_17 >= phase_start_16
if A_lvl_idx[A_lvl_q] < phase_start_16
A_lvl_q = Finch.scansearch(A_lvl_idx, phase_start_16, A_lvl_q, A_lvl_q_stop - 1)
if phase_stop_17 >= phase_start_6
if A_lvl_idx[A_lvl_q] < phase_start_6
A_lvl_q = Finch.scansearch(A_lvl_idx, phase_start_6, A_lvl_q, A_lvl_q_stop - 1)
end
while true
A_lvl_i = A_lvl_idx[A_lvl_q]
Expand Down Expand Up @@ -244,9 +244,9 @@ begin
end
end
end
phase_start_19 = max(11, 1 + A_lvl.shape)
phase_start_8 = max(11, 1 + A_lvl.shape)
phase_stop_21 = min(C_lvl.shape, 10 + B_lvl.shape)
if phase_stop_21 >= phase_start_19
if phase_stop_21 >= phase_start_8
B_lvl_q = B_lvl_ptr[1]
B_lvl_q_stop = B_lvl_ptr[1 + 1]
if B_lvl_q < B_lvl_q_stop
Expand All @@ -255,9 +255,9 @@ begin
B_lvl_i1 = 0
end
phase_stop_22 = min(10 + B_lvl_i1, phase_stop_21)
if phase_stop_22 >= phase_start_19
if B_lvl_idx[B_lvl_q] < phase_start_19 + -10
B_lvl_q = Finch.scansearch(B_lvl_idx, phase_start_19 + -10, B_lvl_q, B_lvl_q_stop - 1)
if phase_stop_22 >= phase_start_8
if B_lvl_idx[B_lvl_q] < phase_start_8 + -10
B_lvl_q = Finch.scansearch(B_lvl_idx, phase_start_8 + -10, B_lvl_q, B_lvl_q_stop - 1)
end
while true
B_lvl_i = B_lvl_idx[B_lvl_q]
Expand Down Expand Up @@ -294,10 +294,10 @@ begin
end
end
end
phase_start_24 = max(1, 11 + B_lvl.shape)
phase_start_12 = max(1, 11 + B_lvl.shape)
phase_stop_26 = min(C_lvl.shape, 0)
if phase_stop_26 >= phase_start_24
for i_39 = phase_start_24:phase_stop_26
if phase_stop_26 >= phase_start_12
for i_39 = phase_start_12:phase_stop_26
if C_lvl_qos > C_lvl_qos_stop
C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
Finch.resize_if_smaller!(C_lvl_idx, C_lvl_qos_stop)
Expand All @@ -309,9 +309,9 @@ begin
C_lvl_qos += 1
end
end
phase_start_25 = max(1, 11 + B_lvl.shape)
phase_start_13 = max(1, 11 + B_lvl.shape)
phase_stop_27 = min(C_lvl.shape, A_lvl.shape)
if phase_stop_27 >= phase_start_25
if phase_stop_27 >= phase_start_13
A_lvl_q = A_lvl_ptr[1]
A_lvl_q_stop = A_lvl_ptr[1 + 1]
if A_lvl_q < A_lvl_q_stop
Expand All @@ -320,9 +320,9 @@ begin
A_lvl_i1 = 0
end
phase_stop_28 = min(A_lvl_i1, phase_stop_27)
if phase_stop_28 >= phase_start_25
if A_lvl_idx[A_lvl_q] < phase_start_25
A_lvl_q = Finch.scansearch(A_lvl_idx, phase_start_25, A_lvl_q, A_lvl_q_stop - 1)
if phase_stop_28 >= phase_start_13
if A_lvl_idx[A_lvl_q] < phase_start_13
A_lvl_q = Finch.scansearch(A_lvl_idx, phase_start_13, A_lvl_q, A_lvl_q_stop - 1)
end
while true
A_lvl_i = A_lvl_idx[A_lvl_q]
Expand Down Expand Up @@ -358,10 +358,9 @@ begin
end
end
end
phase_start_29 = max(1, 1 + A_lvl.shape, 11 + B_lvl.shape)
phase_stop_32 = C_lvl.shape
if phase_stop_32 >= phase_start_29
for i_47 = phase_start_29:phase_stop_32
phase_start_16 = max(1, 1 + A_lvl.shape, 11 + B_lvl.shape)
if C_lvl.shape >= phase_start_16
for i_47 = phase_start_16:C_lvl.shape
if C_lvl_qos > C_lvl_qos_stop
C_lvl_qos_stop = max(C_lvl_qos_stop << 1, 1)
Finch.resize_if_smaller!(C_lvl_idx, C_lvl_qos_stop)
Expand Down
Loading
Loading