[GSoC] Julia wrapper #5824
Replies: 11 comments 20 replies
-
If you haven't already tried these out, the tutorials are a good way to get more familiar with Halide. I'm not sure about specific issues that are relevant to you at the moment, but Tzu-Mao recommended trying to understand our PyTorch codegen module as a good starting point. The gitter is a good communication method that we use. |
Beta Was this translation helpful? Give feedback.
-
A bit more on this, specific to Julia: after a quick glance over Cxx.jl and CxxWrap.jl, CxxWrap seems to be the more plausible option for embedding (if there are others who are more familiar with Julia, please correct me). This issue links to some examples that may be relevant |
Beta Was this translation helpful? Give feedback.
-
I plan to follow a similar route OpenCV-Julia binding project did since it's written in C++, too. So yeah I'll use CxxWrap. But before that, I'll need to try and learn the halide internals to understand it. I'll do a halide-Julia benchmark first in the next few days. Hopefully, I can put my hands on the wrapper project next weekend. |
Beta Was this translation helpful? Give feedback.
-
Sorry if I'm asking the wrong question. Does Halide provide a C API? If so it's very possible that we could get rid of CxxWrap dep and thus make things easier. |
Beta Was this translation helpful? Give feedback.
-
I see both It seems that if I take the CxxWrap way, I'm doing a CxxWrap-version of |
Beta Was this translation helpful? Give feedback.
-
@vchuravy If it's not too complicated, may I ask will this be an issue for Halide? Or I have to build Julia from scratch just like https://github.com/vchuravy/MLIR.jl? I'm not familiar with LLVM at all so have no idea what would happen if I use my own LLVM instead of Julia's shared LLVM. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to pass the Halide Buffer as a Julia Array? I did some experiment by passing the pointer to internal julia> using Halide.CppBindings: _Buffer
julia> data = _Buffer.Buffer{Float32}((4, 4))
Halide.CppBindings._Buffer.BufferAllocated{Float32}(Ptr{Nothing} @0x0000000003005570)
julia> make_array(data) = unsafe_wrap(Array{Float32, 2}, Ptr{Float32}(_Buffer.get_buffer_host(data).cpp_object), (4, 4); own=true)
julia> A = make_array(data)
4×4 Matrix{Float32}:
1.68832f25 1.66783f19 7.14788f22 1.13189f21
1.06028f-38 1.76852f19 1.2867f22 7.00624f22
1.10953f27 7.17676f31 1.15879f24 1.28391f22
6.73472f22 1.81781f31 3.02213f32 1.15879f24 I'm really not sure if this is legal from Halide side because the ownership is unclear to me. |
Beta Was this translation helpful? Give feedback.
-
halide_buffer_t doesn't have any reference counting or anything, so it definitely doesn't own the data Halide::Buffer and Halide::Runtime::Buffer own the data in the cases where they do the malloc, and don't own the data in the cases where they're given a pointer. So in your example above I think Halide Buffer owns the data, and Julia just gets a view of it (but Julia owns the Halide::Buffer object itself). If you can hide the fact that Halide::Buffer even exists from Julia users and just make everything accept and return Julia arrays, that seems like it would be even better. In that case any Halide::Buffer objects constructed under the hood would be non-owning. |
Beta Was this translation helpful? Give feedback.
-
Here it comes (it's just a preview so the usage and information will be definitely get improved): julia> f = Func("Blur");
julia> x, y = Var("x"), Var("y");
# Julia doesn't support assignment operator `=`
# a workaround is to make it a 0-dimensional array and override the `setindex!`[] operator
julia> f[x, y][] = x + y;
julia> result = realize(f, (4, 4))[0];
julia> result_view = unsafe_wrap_from_buffer(Int32, result)
4×4 Matrix{Int32}:
0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6 So at least the minimal JIT example works now and I haven't met the LLVM symbolic issue so far. I'll try the AOT example tomorrow and see if it works, but I want to investigate the BinaryBuilder system in the following few days and come up with the proposal. One key difference that shows up here is that Julia uses 1-based indexing, so technically, the result in Julia should be 4×4 Matrix{Int64}:
2 3 4 5
3 4 5 6
4 5 6 7
5 6 7 8 Question: Should I automatically offset the indexes to suit the Julia 1-based assumption, or just note this difference somewhere in the documentation? I prefer to do auto offset because it would work more smoothly with other Julia array types. |
Beta Was this translation helpful? Give feedback.
-
I still think we need one (maybe two) separate repos for the Julia bindings. The first repo is for the Julia source codes (and potentially documentation), I still think it's necessary for the following two reasons:
The (optional) second repo is to host the generated library built by BinaryBuilder. Currently, every binary dependency is built with JuliaLang's buildbot and released in a separate repo in https://github.com/JuliaBinaryWrappers with For clarification, my final goal of this project is to let users do (@v1.6) pkg> add FFTW
Installing known registries into `tmp`
Added registry `General` to `tmp/registries/General`
Resolving package versions...
Installed IntelOpenMP_jll ─ v2018.0.3+2
Installed MKL_jll ───────── v2021.1.1+1
Installed FFTW_jll ──────── v3.3.9+7
Installed AbstractFFTs ──── v1.0.1
Installed Reexport ──────── v1.0.0
Installed JLLWrappers ───── v1.2.0
Installed FFTW ──────────── v1.3.2 |
Beta Was this translation helpful? Give feedback.
-
@johnnychen94 Is the email address linked on your github accurate? We should probably discuss writing the proposal |
Beta Was this translation helpful? Give feedback.
-
Hi,
My name is Jiuning Chen(Johnny Chen), I'm a second-year Ph.D. student in ECNU(East China Normal University), a GSoC 19 student in Julia, and also a core maintainer of JuliaImages since that. My previous main research interest is low-level image processing (e.g., denoise) using filter techs.
Both Julia and halide have shown their great advantages in image processing and I want to see if I can try to get the best of the two worlds by providing a Julia interface to Halide.
I've learned a lot from the halide paper when I try to optimize my Julia codes but never tried halide; it was quite a long time ago since my last usage of C++. To apply for the Halide Code Generation For More Languages GSoC project, I definitely need some refresh of my C++ knowledge, I'm wondering if you could provide some easy-to-start issues that I can work on to get a better understanding of halide (and of course C++) before I start to write my proposal.
Also, is this issue an appropriate place to update progress, or should I contact you via other channels/apps?
Best regards
cc: @zvookin @rootjalex @BachiLi
Beta Was this translation helpful? Give feedback.
All reactions