Closed chriselrod closed 5 years ago
I haven't tried the source build on Julia v1.2 yet, so have no idea about the segment fault. Cxx.jl may need to be patched for Julia v1.2 compatibility. Also, it might be caused by certain mistakes committed when I was merging bootstrap.cpp
's code from the BB2 version. Could you revert bootstrap.cpp
to this commit and apply #407 and then try it again?
That works, although there's still some old pre-Julia 1.0 in there:
julia> cxx"""
#include <iostream>
class Hello {
public:
void hello_world(const char *now) {
std::string snow = now;
std::cout << "Hello, World! Now is " << snow << std::endl;
}
};
"""
true
julia> hello_class = @cxxnew Hello()
Error showing value of type Cxx.CxxCore.CppPtr{Cxx.CxxCore.CppValue{Cxx.CxxCore.CxxQualType{Cxx.CxxCore.CppBaseType{:Hello},(false, false, false)},N} where N,(false, false, false)}:
ERROR: UndefVarError: Void not defined
The show method has been fixed on master.
Also, as aside, what's the easiest way to map simple C++ structs to Julia, eg __m256d
from immintrin.h
<=> NTuple{4,Core.VecElement{Float64}}
? Ie, these are bitcastable, and equivalent across a ccall
. But here I get:
ERROR: Got bad type information while compiling Cxx.CxxCore.CppNNS{Tuple{:xserf_512d}} (got NTuple{8,VecElement{Float64}} for argument 1)
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] check_args at /home/chriselrod/.julia/dev/Cxx/src/codegen.jl:447 [inlined]
[3] _cppcall(::Type, ::Type, ::Bool, ::Bool, ::Tuple{DataType}) at /home/chriselrod/.julia/dev/Cxx/src/codegen.jl:516
[4] #s37#39(::Any, ::Any, ::Any, ::Any) at /home/chriselrod/.julia/dev/Cxx/src/codegen.jl:841
[5] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:524
[6] erf(::NTuple{8,VecElement{Float64}}) at ./REPL[6]:1
[7] top-level scope at REPL[8]:1
and I'm sure there's some reasonable way to do that.
Similarly, what about mapping templates to Julia parameteric structs?
Is this possible, and is there documentation / examples illustrating that? I confess I'm new to Julia-C++ interop. Earlier, I'd always just compile shared libraries (using extern "C"
) and ccall
them.
I'm merging this PR and gonna roll back those changes later on.
As for the question, could you elaborate a little bit more about what you would like to do? Could you post the MWE that was complaining about those errors?
Basically, Cxx.jl allows you to write C++ code in Julia, which means you could write Julia functions encapturing some C++ code. Here is a keno's old repo that demonstrates how to write a wrapper using Cxx.jl.
That works, although there's still some old pre-Julia 1.0 in there:
I just reverted those changes. Now you could use Cxx.jl's master with everything fixed. Also, don't forget to apply PR407 manually before rebuilding since it's not merged to master yet.
Strange. All the tests passed when I did a source build on Julia 1.2 without patching PR407. The following is my Julia version info:
Version 1.2.0-pre.0 (2019-04-11)
release-1.2/8a84ba5018* (fork: 1 commits, 28 days)
Interesting. That is exactly what I have:
Version 1.2.0-pre.0 (2019-04-11)
release-1.2/8a84ba5018* (fork: 1 commits, 28 days)
...and, I just retried Cxx master (without applying PR407), and it works.
As for the question, could you elaborate a little bit more about what you would like to do? Could you post the MWE that was complaining about those errors?
Here is a MWE for that error:
using Cxx
cxxinclude("immintrin.h")
cxx"""
__m256d add256(__m256d a, __m256d b){
return _mm256_add_pd(a, b);
}
"""
add(a::NTuple{4,Core.VecElement{Float64}}, b::NTuple{4,Core.VecElement{Float64}}) = @cxx add256(a, b)
x4 = ntuple(Val(4)) do i Core.VecElement(randn(Float64)) end;
y4 = ntuple(Val(4)) do i Core.VecElement(randn(Float64)) end;
add(x4, y4)
# ERROR: Got bad type information while compiling Cxx.CxxCore.CppNNS{Tuple{:add256}} (got NTuple{4,VecElement{Float64}} for argument 1)
I'm interested in wrapping many of the math functions in the xsimd library.
I wrote a library that compiles a shared library to call many of these with ccall
, but Cxx
is probably a better solution. Especially if xsimd::batch<T,N>
and NTuple{N,Core.VecElement{T}}
are interoperable.
is it feasible to directly use vcpp"__m256d"
as wrapper function's argument type instead of Core.VecElement
? e.g. add(a::vcpp"__m256d", b::vcpp"__m256d") = @cxx add256(a, b)
.
Adding an additional triple. The path on Clear Linux version 29310 to the gcc libraries is
/usr/lib64/gcc/x86_64-generic-linux/9/
.Note that while I can build Cxx, I don't have it working yet locally. However, I imagine this PR should be fine.
My experience with gdb is extremely limited: