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

TensorOperationscuTENSORExt fails to compile #174

Closed
OliverDudgeon opened this issue May 20, 2024 · 4 comments · Fixed by #182
Closed

TensorOperationscuTENSORExt fails to compile #174

OliverDudgeon opened this issue May 20, 2024 · 4 comments · Fixed by #182

Comments

@OliverDudgeon
Copy link

Hi,

I'm running into a strange problem with the TensorOperations cuTENSOR package extension. It will fail to compile with this specific package setup.

I have a package (lets call it MyPackage) that depends on TensorOperations but is generic and doesn't require CUDA. Then MyPackage has a package extension called MyPackageCUDAExt which has CUDA (but not cuTENSOR) as a dependency. When loading this package using MyPackage with the MyPackage environment activated, precompilation of TensorOperations fails.

┌ Error: Error during loading of extension TensorOperationscuTENSORExt of TensorOperations, use Base.retry_load_extensions() to retry.
│   exception =
│    1-element ExceptionStack:
│    Failed to precompile TensorOperationscuTENSORExt [5a347f6a-6589-5393-bbed-383ac4730ab8] to "~\\.julia\\compiled\\v1.10\\TensorOperationscuTENSORExt\\jl_8FF7.tmp".    
│    Stacktrace:
│      [1] error(s::String)
│        @ Base .\error.jl:35
│      [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
│        @ Base .\loading.jl:2468
│      [3] compilecache
│        @ .\loading.jl:2340 [inlined]
│      [4] (::Base.var"#968#969"{Base.PkgId})()
│        @ Base .\loading.jl:1974
│      [5] mkpidlock(f::Base.var"#968#969"{Base.PkgId}, at::String, pid::Int32; kwopts::@Kwargs{stale_age::Int64, wait::Bool})
│        @ FileWatching.Pidfile ~\.julia\juliaup\julia-1.10.3+0.x64.w64.mingw32\share\julia\stdlib\v1.10\FileWatching\src\pidfile.jl:93
│      [6] #mkpidlock#6
│        @ ~\.julia\juliaup\julia-1.10.3+0.x64.w64.mingw32\share\julia\stdlib\v1.10\FileWatching\src\pidfile.jl:88 [inlined]
│      [7] trymkpidlock(::Function, ::Vararg{Any}; kwargs::@Kwargs{stale_age::Int64})
│        @ FileWatching.Pidfile ~\.julia\juliaup\julia-1.10.3+0.x64.w64.mingw32\share\julia\stdlib\v1.10\FileWatching\src\pidfile.jl:111
│      [8] #invokelatest#2
│        @ .\essentials.jl:894 [inlined]
│      [9] invokelatest
│        @ .\essentials.jl:889 [inlined]
│     [10] maybe_cachefile_lock(f::Base.var"#968#969"{Base.PkgId}, pkg::Base.PkgId, srcpath::String; stale_age::Int64)
│        @ Base .\loading.jl:2983
│     [11] maybe_cachefile_lock
│        @ .\loading.jl:2980 [inlined]
│     [12] _require(pkg::Base.PkgId, env::Nothing)
│        @ Base .\loading.jl:1970
│     [13] __require_prelocked(uuidkey::Base.PkgId, env::Nothing)
│        @ Base .\loading.jl:1812
│     [14] #invoke_in_world#3
│        @ .\essentials.jl:926 [inlined]
│     [15] invoke_in_world
│        @ .\essentials.jl:923 [inlined]
│     [16] _require_prelocked
│        @ .\loading.jl:1803 [inlined]
│     [17] _require_prelocked
│        @ .\loading.jl:1802 [inlined]
│     [18] run_extension_callbacks(extid::Base.ExtensionId)
│        @ Base .\loading.jl:1295
│     [19] run_extension_callbacks(pkgid::Base.PkgId)
│        @ Base .\loading.jl:1330
│     [20] run_package_callbacks(modkey::Base.PkgId)
│        @ Base .\loading.jl:1164
│     [21] __require_prelocked(uuidkey::Base.PkgId, env::String)
│        @ Base .\loading.jl:1819
│     [22] #invoke_in_world#3
│        @ .\essentials.jl:926 [inlined]
│     [23] invoke_in_world
│        @ .\essentials.jl:923 [inlined]
│     [24] _require_prelocked(uuidkey::Base.PkgId, env::String)
│        @ Base .\loading.jl:1803
│     [25] macro expansion
│        @ .\loading.jl:1790 [inlined]
│     [26] macro expansion
│        @ .\lock.jl:267 [inlined]
│     [27] __require(into::Module, mod::Symbol)
│        @ Base .\loading.jl:1753
│     [28] #invoke_in_world#3
│        @ .\essentials.jl:926 [inlined]
│     [29] invoke_in_world
│        @ .\essentials.jl:923 [inlined]
│     [30] require(into::Module, mod::Symbol)
│        @ Base .\loading.jl:1746
│     [31] include(fname::String)
│        @ Base.MainInclude .\client.jl:489
│     [32] top-level scope
│        @ REPL[2]:1
│     [33] macro expansion
│        @ ~\.julia\packages\Alert\TH90I\src\alert_repl.jl:40 [inlined]
│     [34] macro expansion
│        @ ~\.julia\packages\Alert\TH90I\src\at_alert.jl:42 [inlined]
│     [35] top-level scope
│        @ ~\.julia\packages\Alert\TH90I\src\alert_repl.jl:37
│     [36] top-level scope
│        @ ~\.julia\juliaup\julia-1.10.3+0.x64.w64.mingw32\share\julia\stdlib\v1.10\REPL\src\REPL.jl:1428
│     [37] eval
│        @ .\boot.jl:385 [inlined]
│     [38] eval
│        @ .\Base.jl:88 [inlined]
│     [39] repleval(m::Module, code::Expr, ::String)
│        @ VSCodeServer ~\.vscode\extensions\julialang.language-julia-1.79.2\scripts\packages\VSCodeServer\src\repl.jl:229
│     [40] #112
│        @ ~\.vscode\extensions\julialang.language-julia-1.79.2\scripts\packages\VSCodeServer\src\repl.jl:192 [inlined]
│     [41] (::VSCodeServer.var"#111#113"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
│        @ VSCodeServer ~\.vscode\extensions\julialang.language-julia-1.79.2\scripts\packages\VSCodeServer\src\repl.jl:193
│     [42] #invokelatest#2
│        @ .\essentials.jl:892 [inlined]
│     [43] invokelatest(::Any)
│        @ Base .\essentials.jl:889
│     [44] (::VSCodeServer.var"#64#65")()
│        @ VSCodeServer ~\.vscode\extensions\julialang.language-julia-1.79.2\scripts\packages\VSCodeServer\src\eval.jl:34
└ @ Base loading.jl:1301

I tried disabling precompilation with ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0 but this doesn't appear to stop precompilation of package extensions. Additionally, execution fails but the traceback doesn't enter TensorOperations. But this only happens alongside the failed precompilation.

ERROR: LoadError: UndefVarError: `unwrap_type` not defined
Stacktrace:
  [1] Base.Broadcast.BroadcastStyle(W::Type{SubArray{ComplexF64, 1, CuArray{…}, Tuple{…}, false}})
    @ CUDA ~\.julia\packages\CUDA\jdJ7Z\src\broadcast.jl:10
  [2] combine_styles
    @ .\broadcast.jl:460 [inlined]
  [3] combine_styles(c1::SubArray{…}, c2::Base.Broadcast.Broadcasted{…})
    @ Base.Broadcast .\broadcast.jl:461
  [4] materialize!
    @ .\broadcast.jl:911 [inlined]
  [5] apply_gate(g::CuArray{…}, A::CuArray{…}, sAB::CuArray{…}, B::CuArray{…}, sBA::CuArray{…}; rtol::Float64, cutoff_method::Symbol)
    @ MyPackage ~\.julia\dev\MyPackage\src\tensorstuff.jl:8
  [6] macro expansion
    @ ~\.julia\dev\MyPackage\src\tensorstuff.jl:129 [inlined]

If I create a temporary environment with ]activate --temp and add CUDA, cuTENSOR and ]dev MyPackage then loading TensorOperations runs as expected. So it's only a problem when loading TensorOperations from within an environment that itself defines a package extension with a dependency on CUDA.

Is there something I'm doing wrong with my package setup or is something else going on?

Thank you!

Project.toml:

[deps]
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
QuantumOptics = "6e0679c1-51ea-5a7c-ac74-d61b76210b0c"
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
Tullio = "bc48ee85-29a4-5162-ae0b-a64e1601d4bc"

[weakdeps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"

[extensions]
MyPackageCUDAExt = "CUDA"

[compat]
JLD2 = "^0.4.45"
PrecompileTools = "^1.2.0"
ProgressLogging = "^0.1.4"
QuadGK = "^2.9.4"
TensorOperations = "^4.1.0"
Tullio = "^0.3.7"
julia = "1.8"

[extras]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
NPZ = "15e1cf62-19b3-5cfa-8e77-841668bca605"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"

[targets]
test = ["Test", "NPZ", "QuadGK", "CUDA", "cuTENSOR"]
@lkdvos
Copy link
Collaborator

lkdvos commented May 21, 2024

Hi Oliver,
I have to admit I've never seen this before, and I am not entirely sure what's going wrong here. In principle, I would have expected that the extension does not get loaded at all, considering you do not have cuTENSOR loaded(?). Can you check what happens if you remove cuTENSOR from the [extras] section of your Project.toml?

I could try and have a look, but I would need something reproducible to dig a bit deeper.

@OliverDudgeon
Copy link
Author

Sorry I forgot to mention this error occurs when loading cuTENSOR which then triggers both my package extension and TensorOperationscuTENSORExt to load/precompile. This still happens if I remove CUDA and cuTENSOR from [extras]. I'll see if I can put together a minimal example.

@lkdvos
Copy link
Collaborator

lkdvos commented May 21, 2024

This sounds like it might be something about package extensions, if you get a minimal example it might be reasonable to submit an issue to the Julia repo as well

@saman20041998
Copy link

...

@lkdvos lkdvos linked a pull request Jul 12, 2024 that will close this issue
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 a pull request may close this issue.

3 participants