PNaCL

72 views
Skip to first unread message

Ben Goodrich

unread,
Nov 13, 2013, 9:36:45 AM11/13/13
to stan...@googlegroups.com
Now that it is finally officially released (to developers), I think Stan should pursue PNaCL

http://blog.chromium.org/2013/11/portable-native-client-pinnacle-of.html

In short, this is a Google effort that lets you use a LLVM-based compiler to create the intermediate representation of binary-ish code and then Chrome the webbrowser can execute it (in a sandbox) on the major platforms without the end-user having to compile anything or losing much speed. There is also an API for accessing local data files.

I was thinking about using this or emscripten for the missing data thing if IES approves my grant proposal, but I think it would be good for Stan generally. People could distribute (or host) Stan models this way and http://mc-stan.org could live-demonstrate all of Stan's examples (in whatever color scheme).

What we need is some 12 year old HTML5 speaking little dude to write an app that would provide a high-level interface to calling an arbitrary Stan model (and then print samples*.csv), like what we do with RStan and PyStan except more GUI-ish for the web-based user. If we could find a guy like that (wouldn't need to know stats), then that effort could proceed in parallel to the rest of the stuff we are doing and wouldn't be all that difficult to maintain going forward since it would basically just be calling command-line Stan within a browser.

Ben

Michael Betancourt

unread,
Nov 13, 2013, 1:19:49 PM11/13/13
to stan...@googlegroups.com
Or a Google Summer of Code project. I think we have enough self-contained projects
that we might consider applying (I can't remember if we have to pay at all). If
Shogun can get a bunch of students I don't see why we can't.
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Bob Carpenter

unread,
Nov 13, 2013, 2:30:41 PM11/13/13
to stan...@googlegroups.com
That sounds awesome. And downright Java-like, though
it sounds like a one-time compile to plaform rather than
a JIT model. (Julia's running on the JIT model.)

I'm curious what the speed is. Even if it's only like
what clang can produce at -O0 or below,
it'd still be great to build. Especially for teaching
contexts where the native installations are a pain.

Does "LLVM-based" mean we can use all the templates
and everything else we have?

Mitzi's looking for a project while we're in Paris and this
sounds like a good one for a web developer who knows some
stats. I'm bcc-ing her on the message.

- Bob

Ben Goodrich

unread,
Nov 13, 2013, 6:25:41 PM11/13/13
to stan...@googlegroups.com
I can't retain a bcc, but I trust that Bob can reforward (although I did not mean to imply that Mitzi would be a 12 year old HTML5 speaking little dude). It is a one-time semi-compile to an intermediate representation and then Chrome can execute from the intermediate representation on any prevalent platform. You can use optimization when building and it is something like a 5% slowdown relative to native on average for the projects that have been tested (they are mostly targeting games, so who knows about stat computing). Last time I checked (a few months ago), test-unit was passing with their forked llvm / clang semi-compiler; Google definitely intends that you not have to make (m)any changes to your codebase.

Ben

Ben Goodrich

unread,
Jan 19, 2014, 8:13:38 PM1/19/14
to stan...@googlegroups.com
On Wednesday, November 13, 2013 9:36:45 AM UTC-5, Ben Goodrich wrote:
Now that it is finally officially released (to developers), I think Stan should pursue PNaCL

http://blog.chromium.org/2013/11/portable-native-client-pinnacle-of.html

In short, this is a Google effort that lets you use a LLVM-based compiler to create the intermediate representation of binary-ish code and then Chrome the webbrowser can execute it (in a sandbox) on the major platforms without the end-user having to compile anything or losing much speed. There is also an API for accessing local data files.

Daniel,

I have a branch that almost has this working. I have this in make/os_linux

ifeq (nacl,$(CC_TYPE))
  CFLAGS
+= -DBOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK=1 -DBOOST_HAS_GETTIMEOFDAY=1
  EXE
= .pexe
endif

But that just gets it to compile to the intermediate representation. So, test-unit will compile everything but not be able to execute anything.

To use or test the result, there are two more steps outlined here

https://groups.google.com/d/msg/native-client-discuss/jorIid52Se0/Gc-LsKot8RsJ

So basically, we need to makefile to notice that whenever there is a .pexe file, to do the two more steps. I put this into the makefile

##
# Tell make how to compile a .pexe file.
##
% : %.pexe
        $
(patsubst %clang++,%finalize,$(CC)) -o $< $<
        $
(patsubst %clang++,%translate,$(CC)) -arch linux-x86-32 -o $< $<

but that rule seems to never run.

Ben

Daniel Lee

unread,
Jan 19, 2014, 8:26:47 PM1/19/14
to stan...@googlegroups.com
Yeah -- I've had to deal with this a lot. In makefiles, you can't use the pattern rules with a match-all pattern on the left (%). You need to make it a static pattern rule by specifying which targets need this rule. For example
   test/foo/bar : % : %.pexe

I'm not sure if the targets are specified correctly, though. I'll have to go give it a closer look. Can you write up what you're intending it to do and what you've done so I don't have to dig too deeply? It looks like you're trying to use the EXE variable when you probably shouldn't. That was created for cross-platform compatibility. For Windows, the build targets look like Mac/Linux targets, but with a .exe at the end.

Ben Goodrich

unread,
Jan 19, 2014, 8:50:54 PM1/19/14
to stan...@googlegroups.com

OK, but it is essentially all targets that need a rule. The main goal at this point is to be able to run test-all with the pnacl compiler. Then we could propose an interface as a GSOC project, which I think would be the most attractive thing in Google's eyes because they are trying to push pnacl and lots of undergrads know HTML.

To reiterate,
  • pnacl-clang++ outputs an intermediate representation of the code
  • pnacl-finalize takes the intermediate representation and creates a platform-independent representation
  • Chrome the webbrowser can execute that on all platforms
but that is impossible to automatically test because you have to launch Chrome and we don't have the necessary HTML written yet. Instead,

https://groups.google.com/d/msg/native-client-discuss/jorIid52Se0/Gc-LsKot8RsJ

says that we can use pnacl-translate to take the output of pnacl-finalize and make it into an executable that runs (on 32 bit Linux for now).

So, there are two additional steps to undertake basically everywhere


$(patsubst %clang++,%finalize,$(CC)) -o $< $<
$
(patsubst %clang++,%translate,$(CC)) -arch linux-x86-32 -o $< $<

but those two steps only should be run when $(CC_TYPE) is pnacl.

Maybe the thing to do is add those two lines after everywhere that $(LINK.c) is called but condition them on $(CC_TYPE) ?

Ben


Reply all
Reply to author
Forward
0 new messages