JIT compilation of ispc code.

84 views
Skip to first unread message

Syoyo Fujita

unread,
Sep 4, 2011, 11:24:44 PM9/4/11
to ispc...@googlegroups.com
Hello ispc'ers,

I am planning to use ispc as a shading language(for my own rendering
platform), thus want to do JIT compilation of ispc code through LLVM
framework.
Is there any good idea to do that?

FYI, I tried to investigate JIT compilation of RenderMan shading
language using LLVM few years ago.

http://vimeo.com/3294472
http://lucille.svn.sourceforge.net/viewvc/lucille/angelina/rsl2llvm/
(source code)
http://www.slideshare.net/syoyo/rsltollvm?src=embed (presentation slide)

Similar procedure could be applied to implement JIT compilation of ispc code.

Thanks,
Syoyo

Matt Pharr

unread,
Sep 8, 2011, 12:03:24 AM9/8/11
to ispc...@googlegroups.com
On Sep 4, 2011, at 8:24 PM, Syoyo Fujita wrote:

Hello ispc'ers,

I am planning to use ispc as a shading language(for my own rendering
platform), thus want to do JIT compilation of ispc code through LLVM
framework.
Is there any good idea to do that?

A lot of the building blocks are available between the main ispc executable and the ispc_test executable; in other words, ispc can take ispc source code all the way to LLVM IR (stored in the llvm::Module * in m->module, e.g. when Module::WriteOutput is called), and then ispc_test is more or less a simple example of using the LLVM JIT with a llvm::Module (loaded from a bitcode file in that case, but you could combine the two together into a single program…)

One issue that your investigations of RenderMan with LLVM identified was shader specialization based on parameter values; there isn't code to do that with ispc yet implemented, unfortunately.  One option would be to generate additional LLVM IR function calls and then apply LLVM's inlining and then constant propagation passes.  In other words, given something (in LLVM IR) like:

declare float @foo(float, i32, [a bunch of parameters]) { 
   …
}

If you wanted a specialized version of foo based on that i32 having the value 0, you could emit a function like:

declare float @foo_specialized_arg1_0(float, [a bunch of parameters]) {
  %r = call float @foo(float %0, i32 0, [additional parameters])
  ret float %r
}

And you should then get what you're hoping for.

Another issue is having LLVM free up all of its intermediate memory but not free up the buffer it used to emit the JITted code into.  See this thread on the LLVM mailing list for details: http://thread.gmane.org/gmane.comp.compilers.llvm.devel/33981/focus=34130.

One final note is that as of very recently, LLVM's AVX support is quite solid for static compilation, but it seems that the JIT hasn't kept up.  Presumably the JIT will support AVX codegen at some point, but if that is a concern, that's also something to know about…

-matt
Reply all
Reply to author
Forward
0 new messages