News for hackers. Stuff that matters.
Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by al2o3cr on Sunday March 05, 2017 @09:34PM (#13800312)

    A key feature of AnyDSL is that transformations of code from higher level of abstractions to lower levels is not done in a compiler
Look, you can call it a "mumbleencabulator" if you want, it's still quacking an awful lot like a compiler...
Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by SomeCallMeTim on Sunday March 05, 2017 @11:27PM (#13800701)
Yeah, I tend to agree. I tried reading it even more closely, and here's how I'm interpreting it:

* In a normal compiler, you have the front-end which generates intermediate code in a pseudo-assembly language, and you have the back end that compiles that intermediate code into assembly language (or into JVM or CLR or even JavaScript, these days...)

* In AnyDSL, the front end takes the code and compiles it into, well, the same language, only with decreasing levels of abstraction from the hardware.

I don't know if you're familiar with "shader" languages (for OpenGL and DirectX and similar), but they're written in a syntax that looks very much like C. It's not precisely C, but it looks a whole lot like C -- but every statement effectively generates machine code directly, and they get executed in parallel. So if you're writing a pixel shader that makes everything more red, you'd write a statement like (pseudocode):

    output.r += 10;
...and when it drew the texture or polygon to the screen, it would execute your code once for each pixel.

In AnyDSL, it looks like the top level language is very much like a normal (functional) language. That language gets "compiled" into an intermediate abstraction language (like the one using @iterate call), and the final "compilation" step is like the shader language, in that it's letting you define a target-specific implementation, which could include vector functions or pixel shaders or whatever.

If this were C, then the second level would be internal to the compiler and completely opaque, and the final level would be the compiler backend+libraries, which might have calls to implement vector math. If you imagine lifting those backend libraries up into the same compiler, where the libraries are written in a similar language syntax, you can imagine that they can do a lot more to optimize the result, because more of the code gets built at the same time, and a lot of intermediate states can be eliminated at compile time.

But yes, it still feels fundamentally like a compiler. Only a compiler where you can't just link in existing C-based libraries, because then it wouldn't be able to do its magic. So you therefore need to reinvent all the wheels?

Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by kagebe on Monday March 06, 2017 @06:23AM (#13801980)
In most compilers today, the front-end generates an AST, from which an(other) intermediate representation (IR, named Thorin in AnyDSL[1]) is generated. On that IR, the "middle-end" already optimizes a lot and the back-end finally generates whatever output formats the compiler targets (for AnyDSL: LLVM, CUDA/NVVM, OpenCL).

> * In AnyDSL, the front end takes the code and compiles it into, well, the same language, only with decreasing levels of abstraction from the hardware.

The AnyDSL language (Impala) compiler works exactly like my compiler description above. However, the levels of abstraction you refer to here, are all written in the same "top level" language (a "host" language in DSL literature terms) and are basically just libraries on top of each other. The @ on the iterate call partially evaluates the call (aggressive inlining and specialization) at compile time on the Thorin IR. This feature allows the compiler to remove the layers of abstraction again and bake the code together, like you say.

> But yes, it still feels fundamentally like a compiler. Only a compiler where you can't just link in existing C-based libraries, because then it wouldn't be able to do its magic. So you therefore need to reinvent all the wheels?

Yes, it is a compiler - but you don't need to write one for your DSL (unless you really need other syntax). You're correct with regard to external libraries: If you need to remove the abstraction overhead (e.g. function calls) of your external library for performance reasons you'd need to re-implement that in AnyDSL. However, that holds true for any DSL framework and compiler, unless you compile everything to (C) binaries and do partial evaluation at link time. But at that point you've already lost a lot of information that a compiler can usefully exploit to generate better code: more abstract types, higher-order functions, scheduling info, alias info, etc..

[1] See the paper: http://compilers.cs.uni-saarland.de/papers/lkh15_cgo.pdf

Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by SomeCallMeTim on Monday March 06, 2017 @01:49PM (#13805016)
>However, that holds true for any DSL framework and compiler, unless you compile everything to (C) binaries and do partial evaluation at link time. But at that point you've already lost a lot of information that a compiler can usefully exploit to generate better code: more abstract types, higher-order functions, scheduling info, alias info, etc..

For quite some time, C and C++ linkers have had the ability to look back at the original C/C++ code and literally rebuild the code differently to optimize the program across objects. In the Microsoft compile chain this is called "Global Optimizations". So I don't see AnyDSL's ability to do the same as a completely unique proposition.

The other issue that I see with this is that 98% of code doesn't need to be optimized down to the level that AnyDSL enables. JIT compilers are really good at optimizing the execution path without having to involve programmers at the intermediate and low levels, for example.

In the few cases where you need to target LLVM, CUDA and OpenCL for a particularly performance critical routine, I could see this as being useful, as long as the resulting code can be called from a more standard language. I'd like to see really trivial C bindings (via exported .h files) at a minimum, but C++, Go, Rust, JavaScript, Python, and other modern languages could really hit the performance required of 98% of the code, leaving only the extreme performance code for something like AnyDSL.

But I'd say that front-and-center: "AnyDSL is about creating ultra optimized cross-hardware performance critical code, targeting LLVM, CUDA, and OpenCL code based on the same high level code." All of the talk about theory is just distracting people from the actual "killer app" of AnyDSL.

Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by kagebe on Monday March 06, 2017 @02:15PM (#13805186)
Partial evaluation (whether online/offline) is not implemented in any (current) C/C++/Rust compiler, for very good reasons. "Global Optimizations" may do a significant number of optimizations that partial evaluation may do and some that partial evaluation is unable to do (depending on your abstractions, e.g. code motion).

I totally agree that these kinds of optimizations are unnecessary for most applications, which is why we target and compare against High-Performance Computing algorithms and DSLs. Have a look at the publications and comparisons with OpenCV and similar.

If you want to wrap AnyDSL HPC code with some other language, sure. There is an experimental compiler flag --emit-c-interface right now. :)

However, most of the current HPC DSL frameworks generate some C code from Python/etc by stitching together library calls to BLAS/etc. in some haphazard, mostly untyped way - not ideal.

> But I'd say that front-and-center: "AnyDSL is about creating ultra optimized cross-hardware performance critical code, targeting LLVM, CUDA, and OpenCL code based on the same high level code." All of the talk about theory is just distracting people from the actual "killer app" of AnyDSL.

Thanks, I agree. Presentation could definitely use some work. As it stands, it's mostly a presentation of the published research work and not yet addressed to users.

Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by mikkom on Monday March 06, 2017 @02:25AM (#13801211)
> * In AnyDSL, the front end takes the code and compiles it into, well, the same language, only with decreasing levels of abstraction from the hardware.

I thought this was called a macro.

Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by sddfd on Monday March 06, 2017 @02:51AM (#13801305)
The exact point is that instead of macros, higher-order functions are used.
Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by pka on Monday March 06, 2017 @05:14AM (#13801763)
Why can't you use higher-order functions in macros?
Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by sddfd on Monday March 06, 2017 @02:55AM (#13801321)
Basically the idea is that a compiler that does partial evaluation and can generate extremely efficient code for higher-order functions provides a nice framework for Deals.

I wouldn't call it reinventing the wheel.

Re:AnyDSL: A Framework for Rapid Development of Domain-Speci... by SomeCallMeTim on Monday March 06, 2017 @01:38PM (#13804916)
It's reinventing the wheel if you need rewrite functionality that's otherwise available in C libraries.

Has anyone who you can trust written encryption code in AnyDSL? If not, then you either need to write it yourself (reinventing the wheel, and generally considered A Bad Idea with encryption code), or you need to call a C library, obviating much of the optimization advantage of using AnyDSL.