Skip to content

Conversation

@VarLad
Copy link
Contributor

@VarLad VarLad commented Nov 28, 2025

Based on #174
Currently filing this as a draft because Bumper.jl integration seems to be broken.

@VarLad
Copy link
Contributor Author

VarLad commented Nov 28, 2025

Okay, never mind, turns out I needed to add @inbounds to the Bumper.jl example...

using Bumper, StaticTools, StaticCompiler

function times_table(argc::Int, argv::Ptr{Ptr{UInt8}})
           argc == 3 || return printf(c"Incorrect number of command-line arguments\n")
           rows = argparse(Int64, argv, 2)            # First command-line argument
           cols = argparse(Int64, argv, 3)            # Second command-line argument

           buf = MallocSlabBuffer()
           @no_escape buf begin
               M = @alloc(Int, rows, cols)
               @inbounds for i=1:rows
                   @inbounds for j=1:cols
                       M[i,j] = i*j
                   end
               end
               printf(M)
           end
           free(buf)
end
       
filepath = compile_executable(times_table, (Int64, Ptr{Ptr{UInt8}}), "./")

@VarLad VarLad marked this pull request as ready for review November 28, 2025 07:08
@VarLad
Copy link
Contributor Author

VarLad commented Nov 28, 2025

This likely has similar issues to:
#174 (comment)

Copy link
Collaborator

@MasonProtter MasonProtter left a comment

Choose a reason for hiding this comment

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

Thanks for trying to revive this @VarLad. I mostly have the same comment as I did for the previous one, so I'll just copy-paste it:

I think it probably doesn't make sense to try and have so many if version(...) checks in here, and we should just increase our version support bounds.

If people aren't able to upgrade to newer versions of julia or GPUCompiler, they will get stuck with older versions of StaticCompiler which is fine.

Also, the pkgversion function was added in v1.9, so using it will break the v1.8 tests.

Since v1.10 is the current julia LTS, I say we drop support for v1.8 and 1.9, and drop support for GPUCompiler < 1.5

That should make this simpler and hopefully more robust too.

Except I'd recommend now that we also drop v1.10 support and move onto v1.11/v1.12 support since there's already a released version that works on v1.10 anyways, and this isn't adding new features that people on 1.10 would want (if anything, it seems that some features have regressed, since it seems you changed some of the tests to remove the possibility of them emitting boundserrors)

Comment on lines 5 to 11
@inline function mul!(C::MallocArray, A::MallocArray, B::MallocArray)
@turbo for n indices((C,B), 2), m indices((C,A), 1)
#@turbo for n ∈ indices((C,B), 2), m ∈ indices((C,A), 1)
@turbo for n indices(C, 2), m indices(C, 1)
Cmn = zero(eltype(C))
for k indices((A,B), (2,1))
# for k ∈ indices((A,B), (2,1))
for k indices(A, 2)
Cmn += A[m,k] * B[k,n]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this removed? Was it to avoid boundserrors causing it to fail to compile? If so, we should see if there's a device_override we could do to help the compiler not get tripped up here.

Copy link
Contributor Author

@VarLad VarLad Nov 28, 2025

Choose a reason for hiding this comment

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

I've reverted this, but both now and on the previous PR, loop_vector related stuff fail to compile

Comment on lines 5 to 12
@inline function mul!(C::StackArray, A::StackArray, B::StackArray)
@turbo for n indices((C,B), 2), m indices((C,A), 1)
# error since Julia v1.11
#@turbo for n ∈ indices((C,B), 2), m ∈ indices((C,A), 1)
@turbo for n indices(C, 2), m indices(C, 1)
Cmn = zero(eltype(C))
for k indices((A,B), (2,1))
# for k ∈ indices((A,B), (2,1))
for k indices(A, 2)
Cmn += A[m,k] * B[k,n]
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

Comment on lines 10 to +11
#Compile dylib
name = repr(fib)
name = string(nameof(fib)) # repr(fib)
Copy link
Collaborator

Choose a reason for hiding this comment

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

did repr stop working?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I see if I use repr:

     Testing Running tests...
Standalone Dylibs: Error During Test at ~/.julia/dev/StaticCompiler/test/testcore.jl:5
  Got exception outside of a @test
  UndefVarError: `name` not defined in `Main`
  Suggestion: check for spelling errors or missing imports.
  Hint: a global variable of this name also exists in LLVM.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Strange

@MasonProtter
Copy link
Collaborator

In the future, if you're reviving old PRs, please make sure you address the review feedback that's already been given on the older version of the PR before re-requesting that someone review it. Because of the amount of time that had past, I didn't immediately recognize that I had already made the exact same review comments back in June, so I spent some time basically just rediscovering the same complaints I already had back then.

@VarLad
Copy link
Contributor Author

VarLad commented Nov 28, 2025

@MasonProtter apologies for wasting time, I forgot about the reviews in last PR. I'll be careful about it in future PRs. 🥲

I've addressed most of the comments. I've removed explicit support for anything pre-1.11 from the codebase.
I've reverted the loopvec based tests (they were failing before, and are still failing)

printdlm function call fails test as well with:

/usr/bin/ld: ./times_table.o: in function `times_table':
start:(.text+0x330): undefined reference to `ijl_error'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@VarLad
Copy link
Contributor Author

VarLad commented Nov 28, 2025

There are a lot of warnings about:

WARNING: llvmcall with integer pointers is deprecated.
Use actual pointers instead, replacing i32 or i64 with i8* or ptr

throughout the codebase 🤔

@brenhinkeller
Copy link
Collaborator

Thanks for taking this on!

@brenhinkeller
Copy link
Collaborator

There are a lot of warnings about:

WARNING: llvmcall with integer pointers is deprecated.
Use actual pointers instead, replacing i32 or i64 with i8* or ptr

throughout the codebase 🤔

Yeah, this is probably due to the switch to opaque pointers in LLVM, and will require a bunch of changes in StaticTools, but I think they should be relatively straightforward/repetitive

@MasonProtter
Copy link
Collaborator

MasonProtter commented Nov 29, 2025

@MasonProtter apologies for wasting time, I forgot about the reviews in last PR. I'll be careful about it in future PRs. 🥲

No problem, and sorry if I came off as grumpy, I was just explaining some best practices for submitting PRs like this.

I've reverted the loopvec based tests (they were failing before, and are still failing)

Looking into this a bit more, it seems that there's been a change to how the errors from indices are handled so that they don't throw a bounderror, that's unfortunate. Here's what happens:

julia> indices(([1, 2], [3, 4, 5]), (1, 1))
ERROR: 2 and 3 are not equal
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:44
 [2] _static_promote
   @ ~/.julia/packages/Static/d7YOk/src/Static.jl:332 [inlined]
 [3] static_promote
   @ ~/.julia/packages/Static/d7YOk/src/Static.jl:330 [inlined]
 [4] static_promote
   @ ~/.julia/packages/Static/d7YOk/src/Static.jl:363 [inlined]
 [5] static_promote
   @ ~/.julia/packages/Static/d7YOk/src/Static.jl:371 [inlined]
 [6] macro expansion
   @ ~/.julia/packages/Static/d7YOk/src/Static.jl:751 [inlined]
 [7] reduce_tup
   @ ~/.julia/packages/Static/d7YOk/src/Static.jl:751 [inlined]
 [8] indices(x::Tuple{Vector{Int64}, Vector{Int64}}, dim::Tuple{Int64, Int64})
   @ StaticArrayInterface ~/.julia/packages/StaticArrayInterface/lkDPR/src/ranges.jl:60
 [9] top-level scope
   @ REPL[3]:1

and the relevant method of _static_promote is here: https://github.com/SciML/Static.jl/blob/master/src/Static.jl#L331C1-L334C4

I would still like some boundschecking in the tests (just to make sure we still eliminate boundserrors) so could you maybe just put

@boundscheck checkbounds(...)

calls into one of the loop vectorization tests? e.g. something like

Base.@propagate_inbounds function mul!(C::StackArray, A::StackArray, B::StackArray)
    @boundscheck begin
        checkbounds(axes(C, 2), axes(B, 2))
        checkbounds(axes(B, 2), axes(C, 2))
        checkbounds(axes(C, 1), axes(A, 1))
        checkbounds(axes(A, 1), axes(C, 1))
        checkbounds(axes(A, 2), axes(B, 1))
        checkbounds(axes(B, 1), axes(A, 2))
    end
    @turbo for n  axes(C, 2), m  axes(C, 1)
        Cmn = zero(eltype(C))
        for k  axes(A, 2)
            Cmn += A[m,k] * B[k,n]
        end
        C[m,n] = Cmn
    end
    return C
end

@VarLad
Copy link
Contributor Author

VarLad commented Nov 30, 2025

@MasonProtter I think even simple loopvec is broke now on StaticCompiler.jl.
I am getting a lot of undefined reference error in this basic example:

using StaticCompiler, StaticTools, LoopVectorization

Base.@propagate_inbounds function loopvec_product(argc::Int, argv::Ptr{Ptr{UInt8}})
    argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
    rows = argparse(Int64, argv, 2)            # First command-line argument
    cols = argparse(Int64, argv, 3)            # Second command-line argument

    s = 0
    @turbo for i=1:rows
        for j=1:cols
           s += i*j
        end
    end
    printf(s)
end

# Attempt to compile
path = compile_executable(loopvec_product, (Int64, Ptr{Ptr{UInt8}}), "./")

(this compiles fine if I remove @turbo)

@MasonProtter
Copy link
Collaborator

Unfortunate. I guess lets just mark those all inside @test_broken blocks for now then

@VarLad
Copy link
Contributor Author

VarLad commented Dec 1, 2025

There's the issue of printdlm erroring in tests, which I have commented out.
Likely related to brenhinkeller/StaticTools.jl#72 and #181 (comment)
I'll take a look at the switch to opaque pointers for StaticTools (and re-enabling printdlm tests here) when I get more time.

@VarLad VarLad requested a review from MasonProtter December 1, 2025 11:16
Copy link
Collaborator

@MasonProtter MasonProtter left a comment

Choose a reason for hiding this comment

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

Almost there! Thanks for sticking with it, just a few nitpicks then we can merge it.

@VarLad
Copy link
Contributor Author

VarLad commented Dec 1, 2025

This is quite weird, StaticCompiler both builds and all tests (pass + broken) work for me locally 🤔

@VarLad VarLad requested a review from MasonProtter December 1, 2025 14:23
@MasonProtter
Copy link
Collaborator

Are you running the integration tests locally?

@VarLad
Copy link
Contributor Author

VarLad commented Dec 1, 2025

Yeah, I just ran it again, I got:

Test Summary:                     | Pass  Broken  Total     Time
Standalone Executable Integration |   18      15     33  4m11.0s
     Testing StaticCompiler tests passed 

I can try commenting out printdlm again, thats the only thing that should've changed here.

@VarLad
Copy link
Contributor Author

VarLad commented Dec 1, 2025

I have commented out printdlm again (and have put a comment about when to re-enable it)
Lets see if that appeases the CI gods....

@brenhinkeller
Copy link
Collaborator

Closes #166

@brenhinkeller
Copy link
Collaborator

I'd say some amount of breakage in integration tests is acceptable given those may need to be fixed on the StaticTools side

@MasonProtter
Copy link
Collaborator

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants