Giter Club home page Giter Club logo

Comments (9)

ihnorton avatar ihnorton commented on May 29, 2024

Apologies for the slow response. I'm kind of puzzled because those structs starting with two underscores should be skipped. Can you add the following so we can figure out what definition this is choking on?

@@ -422,6 +424,7 @@ function wrap_header(wc::WrapContext, topcu::CLCursor, top_hdr, ostrm::IO)
         else
             continue
         end
+        println(name(cursor))
     end
     cindex.cl_dispose(topcl)

from clang.jl.

timholy avatar timholy commented on May 29, 2024

I'm getting a similar error. I inserted the println, here's the gist: https://gist.github.com/timholy/8468205.

from clang.jl.

ihnorton avatar ihnorton commented on May 29, 2024

The underlying problem was poor documentation, but the immediate cause was that header_library only worked properly with a Function. I added a little bit of help so that a function is generated automatically when an ASCIIString is provided. With this and 9c055bb (for a limitation exposed by yaml.h), both of these are now generated cleanly for me.

from clang.jl.

ihnorton avatar ihnorton commented on May 29, 2024

@timholy I used these commands (adding common_file keyword in init):

using Clang
context=wrap_c.init(;output_file="libcudart.jl", common_file="libcudart_h.jl", header_library=x->"libcudart", clang_includes=["/usr/include"], header_wrapped=(x,y)->contains(x,"cuda"))
wrap_c.wrap_c_headers(context, [joinpath("/usr/include","cuda_runtime_api.h")])

from clang.jl.

ihnorton avatar ihnorton commented on May 29, 2024

btw, you are probably aware of this - but just in case: https://github.com/lindahua/CUDA.jl/

from clang.jl.

timholy avatar timholy commented on May 29, 2024

Thanks, Isaiah!

I am aware of Dahua's work, which is really nice. But, I am trying to port an application written in C++ against CUDA-5.0 (Dahua's is 3.2, I think), and after trying to make many conversions I began to wonder if it would just be easier to wrap 5.0.

Sorry to keep troubling you, but one of the things that's missing from the output are some of the complex types, like cudaDeviceProp. Here's my current wrapper-generator:

using Clang
context=wrap_c.init(;output_file="libcudart.jl", common_file="libcudart_h.jl", header_library=x->"libcudart", clang_includes=["/usr/include"], header_wrapped=(x,y)->contains(x,"cuda")||contains(x,"driver"))
path = "/usr/local/cuda-5.0/include"
headers = [joinpath(path, "driver_types.h"), joinpath(path,"cuda_runtime_api.h")]
wrap_c.wrap_c_headers(context, headers)

I verified that clang can indeed parse that file, following your very helpful notebook but with

top = cindex.parse_header("driver_types.h", includes=["/usr/include","/usr/lib/gcc/x86_64-redhat-linux/4.4.4/include"])

For cudaDeviceProp I was able to get all the way through Example 1 without error and with printed output looking promising. So it suggest this is well within Clang's capabilities (which is quite impressive). But I can't find the immutable definition anywhere in the generated files. I also couldn't find any of the much simpler structs, like cudaExtent, so it suggests to me that I'm doing something wrong.

from clang.jl.

timholy avatar timholy commented on May 29, 2024

Never mind! I figured this part out by reading through the sources and adding

context.options = wrap_c.InternalOptions(true)  # wrap structs, too

from clang.jl.

ihnorton avatar ihnorton commented on May 29, 2024

Sorry about that, I will add it as a keyword to the init function so it is more discoverable. You can also do
context.options.wrap_c_structs = true

from clang.jl.

ihnorton avatar ihnorton commented on May 29, 2024

Also, as a word of warning: some of the preprocessor constants will probably require manual editing if they end with "L" or "U". The libclang preprocessor interface is basically "here is the string", and right now wrap_c only does a rudimentary tokenization to exclude unsupportable macro definitions. Unfortunately it does not check the constants yet.

As you may notice, I got rid of the macros, so full functions are printed containing ccalls (in order to be more editable). In some cases it might be useful to disable printing of argument types in the function signature in order to duck-type, because Julia does not do the same kind of auto-promotion for a function as for the special ccall form:

@@ -268,7 +268,8 @@ function wrap(buf::IO, funcdecl::FunctionDecl, libname::ASCIIString)
     function print_args(buf::IO, cursors, types)
         i = 1
         for (c,t) in zip(cursors,types)
-            print(buf, name(c), "::", t)
+            #print(buf, name(c), "::", t)
+            print(buf, name(c))
             (i < length(cursors)) && print(buf, ", ")
             i += 1
         end

from clang.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.