bsc-quantic / Extrae.jl

Julia bindings for extrae Basic API
Apache License 2.0
8 stars 0 forks source link

event register error on extrae call c type conversion #11

Closed clasqui closed 1 year ago

clasqui commented 1 year ago

When registering an event type, this error arises:

ERROR: LoadError: MethodError: Cannot `convert` an object of type Base.RefValue{Vector{Int64}} to an object of type UInt64
Closest candidates are:
  convert(::Type{T}, ::T) where T<:Number at number.jl:6
  convert(::Type{T}, ::Number) where T<:Number at number.jl:7
  convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at twiceprecision.jl:250
  ...
Stacktrace:
  [1] Base.RefValue{UInt64}(x::Base.RefValue{Vector{Int64}})
    @ Base ./refvalue.jl:8
  [2] convert(#unused#::Type{Ref{UInt64}}, x::Base.RefValue{Vector{Int64}})
    @ Base ./refpointer.jl:104
  [3] cconvert(T::Type, x::Base.RefValue{Vector{Int64}})
    @ Base ./essentials.jl:396
  [4] Extrae_define_event_type(type::Int64, type_description::String, nvalues::Int64, values::Base.RefValue{Vector{Int64}}, values_description::Base.RefValue{Vector{String}})
    @ Extrae.FFI ~/Documents/BePPP/cobrexa/Extrae.jl/src/FFI.jl:134
  [5] register(events::Vector{Event{400001, ValueCode} where ValueCode}, desc::String)
    @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:140
  [6] register
    @ ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:132 [inlined]
  [7] init()
    @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:37
  [8] addprocs_extrae(np::Int64; restrict::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/Instrumentation/Distributed.jl:124
  [9] addprocs_extrae(np::Int64)
    @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/Instrumentation/Distributed.jl:120
 [10] top-level scope
    @ ~/Documents/BePPP/cobrexa/Extrae.jl/scripts/test-distributed-work.jl:4

The cause seems to be the conversion of the vector of event values from Ref(Vector{Int64}) to Uint64, which is the type specified in https://github.com/bsc-quantic/Extrae.jl/blob/1ddee26d9b227d8675c558d62debb89b1619cd2b/src/FFI.jl#L134 for the vlaues parameter.

My thought here is that Julia is not interpreting the vector as a pointer, which is something that we straightforward do in C.

clasqui commented 1 year ago

My suggestion here is that, instead of letting @ccall implicitly convert types, we expand the function in FFI to do ourselves the conversion

mofeing commented 1 year ago

I don't think that is necessary. We just need to tell correctly the type. My guess is that instead of

..., values::Ref{Value}, ...

it should be

..., values::Ref{Vector{Value}}, ...

Can you try that?

clasqui commented 1 year ago

Yep, this is what I already tried yesterday in PR #12 This solves the conversion for the values parameter, but then another issue with the conversion of the descs strings vector appears

mofeing commented 1 year ago

Nice! Good catch. Merging now.

clasqui commented 1 year ago

Wait @mofeing !! This was not the only issue with the type conversion in register :sweat_smile: after ai solved the first one, another one appeared! That's what I wanted to discuss with you

mofeing commented 1 year ago

Ahh, okok. Tell me.

clasqui commented 1 year ago

Next one is relative to the conversion of the descs parameter:

ERROR: LoadError: MethodError: no method matching unsafe_convert(::Type{Ptr{Ptr{UInt8}}}, ::Base.RefValue{Vector{String}})
Closest candidates are:
  unsafe_convert(::Type{Ptr{Tv}}, ::SuiteSparse.CHOLMOD.Sparse{Tv}) where Tv at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/SuiteSparse/src/cholmod.jl:296
  unsafe_convert(::Type{Ptr{T}}, ::LinearAlgebra.Transpose{var"#s814", var"#s813"} where {var"#s814", var"#s813"<:(AbstractVecOrMat{T} where T)}) where T at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/adjtrans.jl:222
  unsafe_convert(::Type{Ptr{T}}, ::SharedArrays.SharedArray{T, N} where N) where T at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/SharedArrays/src/SharedArrays.jl:361
  ...
Stacktrace:
 [1] Extrae_define_event_type(type::Int64, type_description::String, nvalues::Int64, values::Vector{Int64}, values_description::Base.RefValue{Vector{String}})
   @ Extrae.FFI ~/Documents/BePPP/cobrexa/Extrae.jl/src/FFI.jl:134
 [2] register(events::Vector{Event{400001, ValueCode} where ValueCode}, desc::String)
   @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:139
 [3] register
   @ ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:132 [inlined]
 [4] init()
   @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:37
 [5] addprocs_extrae(np::Int64; restrict::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/Instrumentation/Distributed.jl:124
 [6] addprocs_extrae(np::Int64)
   @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/Instrumentation/Distributed.jl:120
 [7] top-level scope
   @ ~/Documents/BePPP/cobrexa/Extrae.jl/scripts/test-distributed-work.jl:4
in expression starting at /home/mclasca/Documents/BePPP/cobrexa/Extrae.jl/scripts/test-distributed-work.jl:4
mofeing commented 1 year ago

I did what is suggested in https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/

I think the solution should be similar: remove the Ref(descs) and leave only descs in the register function.

clasqui commented 1 year ago

This shows another error, but I am not sure now if it is the same place (our solution was not correct) or another place (so we solved previous issue).

ERROR: LoadError: MethodError: no method matching String(::Int64)
Closest candidates are:
  String(::String) at boot.jl:350
  String(::Vector{UInt8}) at strings/string.jl:53
  String(::Symbol) at strings/string.jl:83
  ...
Stacktrace:
  [1] description(#unused#::Type{Event{400004, 0}})
    @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:104
  [2] description(#unused#::Event{400004, 0})
    @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:105
  [3] _broadcast_getindex_evalf
    @ ./broadcast.jl:648 [inlined]
  [4] _broadcast_getindex
    @ ./broadcast.jl:621 [inlined]
  [5] _getindex
    @ ./broadcast.jl:645 [inlined]
  [6] _getindex
    @ ./broadcast.jl:644 [inlined]
  [7] _broadcast_getindex
    @ ./broadcast.jl:620 [inlined]
  [8] getindex
    @ ./broadcast.jl:575 [inlined]
  [9] copy
    @ ./broadcast.jl:922 [inlined]
 [10] materialize
    @ ./broadcast.jl:883 [inlined]
 [11] register(events::Vector{Event{400004, ValueCode} where ValueCode}, desc::String)
    @ Extrae ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:138
 [12] register
    @ ~/Documents/BePPP/cobrexa/Extrae.jl/src/API.jl:132 [inlined]
mofeing commented 1 year ago

The error happens because description(::typeof(DistributedHandleEnd)) is not defined. Uploading a fix now.