329 points · by Nelkins · 8y ago · 110 comments
In this way it reminds me of http://futhark-lang.org/ somewhat, though Futhark is explicitly targeted at producing extremely efficient GPU code.
Abstraction by heap allocation is a dead end. It works moderately well on the current generation of computers where CPU is still the dominant driver of computation.
It cannot work for devices like GPUs and the rest coming down the line. Many of the most important computational devices of the future won't support heap allocation so an alternative is needed to draw out their full power. It is of absolute importance that a language for that task have excellent control over inlining. Inlining therefore must comes as guarantee in the language and be a part of the type system.
Inlining is a trade-off that expresses the exchange of memory for computation. It should be the default instead of heap allocating.
I guess whoever is wondering about the why hasn't read the introduction.
> So, in this respect, my programming skill has reached it's limit and the most I will be able to do is refine it.
> And it is embarrassing to me because I want to do better. I am ashamed, but the one to come will have to follow up on what I could not manage with my meager human abilities.
This reminds me of the fictional inspirational process of dwarves in the Drizzt Do'Urden series of books [0] by R. A. Salvatore [1]. In that setting a dwarf craftsman gets only one moment of exceptional divine inspiration in his life to forge a legendary artifact. It is both a blessing and curse for them, because they realize that they will never be able to surpass that work for the remainder of their long lives.
I wonder if other people here have had that moment in their life as well?
That one is really in the "mad scientist" mindset. I love it, I wish him and this project good luck.
I do not actually need more than I have, but I'll keep your link in mind if I ever need random projections though.
For dimensionality reduction, if one were to use my library, the way to go would be the orthogonal JL transform. The key to all these methods is the idea that multiplication by a diagonal matrix and subsequent F[HF]T is equivalent to multiplication by a matrix, which is what allows it to do what random matrix multiplication provides without instantiating or using the full matrix.
As an aside, I admire your work and think it’s both very exciting and highly valuable.
The author states that Spiral "was made for the sake of making a deep learning library which was too difficult to do in F# itself." I wonder what he thinks about DeepML (http://www.deepml.net/), which is a deep learning library written in F#.
The way these projects go is that you start of with an AD library and then when the type system and the language starts getting in the way you either do a lot, and I mean a LOT of engineering with inferior tools or you make something better.
The 'make something better' is always picked and can take various forms. Generally, people would not make a decision to work on a language for a ML library for almost a year before they write down the first line for it. They instead take the middle road of starting with an AD library and gradually extending it.
First they realize that they cannot really express tensors properly with the confines of the language so they make everything symbolic, then they build engines to run such symbolic AST, then they realize that they need JITs and other optimizers to make everything run fast. Tensorflow and PyTorch are currently at this stage. There are more stages after this.
Of course the task of working with ASTs is what a compiler does. I think it is a great pity that Tensorflow and PyTorch are written in C++ under the hood. C++ is probably the worst language I can imagine for working on compilers, so I applaud the authors of DeepML for picking F# instead. Had the TF team picked statically typed functional language for this they could have cut the size of TF by over 10x and saved themselves over a million lines of code.
[ML](https://en.wikipedia.org/wiki/Standard_ML) derivatives like it were made for that sort of thing and I cannot imagine doing Spiral in a non-ML styled language.
The idea is to keep a tape (you can think of it as a list) and then record all the operations on it as you step forward through the program. Then at the end you execute the operations backwards from the tape.
I take this approach in Spiral's ML library.
My apologies for getting a bit philosophical here at the end, but this kind of treatment is among my favorite things to encounter having had the privilege of being born at the cusp of the information age. During the first 50 years of the internet we get to casually encounter foundational new ways of expressing software with increasingly more guarantees and expressability from the languages themselves and reap the benefits of the plumbing and infrastructure that inevitably arises from such. Rust's compile time memory tracking borrow system comes to mind as another such set of compiler based guarantees that we have now that we just didn't have when I was a kid.
tldr: Exciting times to be alive and clicking links on the internet.
https://mastodon.social/@akkartik/100357841646414633 (Mastodon doesn't have in-page anchors, but search for 'memory allocator'.)
> document.querySelectorAll('[id]').length
0
That caught me by surprise. Especially when it has its class entry-center to indicate “this is the actively focused message”, to not load to that point in the page or at least have an ID to jump to there seems surprising.(A pure CSS solution for centering it on the page with an anchor: make the .entry-center `position: relative`, and give it a new child <div id=jump> with CSS `position: absolute; top: calc(50% - 50vh)`. The downside is that if the entire .entry-center is taller than the viewport, it will still be centered on the page, rather than sitting at the top. I suspect that defect could be solved if you used two nodes instead of just one, combining margin and padding, since padding can’t be negative.)
It's very easy to get lost in syntax when transferring from C like languages like JavaScript to F#, some concessions (like Reason has) to semi colons and braces might help those programmers (myself included) to feel at home
constexpr, however, does seem to be enforced.
This:
> Abstraction by heap allocation is a dead end. It works moderately well on the current generation of computers where CPU is still the dominant driver of computation.
> It cannot work for devices like GPUs and the rest coming down the line.
tells me way more about the language (and gets me much more interested) than a "hello world" would.
I think syntax is by far the easiest part of a new language to learn, so it's ultimately not that important.
EDIT: Regardless, it turns out it actually gives code samples like a page or two down.
That said, he gives plenty of examples.
I too need more than a sample and prefer a larger explanation.
Personally I think macro-style staging in statically typed languages is an atrocity and want nothing to do with it. I kind of like the type driven version as is done in LMS, but compared to Spiral the LMS is less expressive.
A lot of work is being done on macros/partial evaluation/staging in Scala and I assume it will continue to be done as the authors are aware of the need for this in a language - without it a functional language would be dog slow, but my impression is that they are having significant difficulties making it fit with Scala's much more complex type system. One consequence of that is that they seemingly rewrite their macro system every few years. This time they will surely get it right despite being at it for decade(s).
The reason why what Spiral has works so well is because its type system is so simple, so staging can be completely intervowen with how it does type inference.
My view based on seeing the last 50 years of language design is that staging is really difficult to bolt onto an already established design. It tends to degenerate into having two languages - the core language and a scripting language on top of it. C++'s template system is the worst example of this. Another example which actually embraces this dichotomy would be [Terra](http://terralang.org/) which could be described as bolting Lua on top of C. I rather dislike this sort of design.
A language needs to be designed around staging from the ground up and it needs to be accepted that in the absence of magic, the programmer will have to mold his style to fit with the new paradigm.
If a language is to have staging it should be everywhere and at all times much like regular type inference is in F# and other ML styled languages.
Well, you are also free to skip the language altogether.
https://github.com/mrakgr/The-Spiral-Language/blob/master/re...
Does the author know anything about julia or how cleanly it allows one to implement things like tensors?
Its type system is definitely less powerful than Spiral's - some of the things you could express naturally in Spiral would require macros in Julia.
All in all, the language strikes me as a better Matlab which I think it succeeds at, but Spiral is made to be a better F#. Some of the tradeoffs I had to make in language design means that I could not succeed at this across the board.
The fact that it has a more powerful type system makes it take an immediate hit in terms of ergonomics, and the language is less pleasant to code in than F# because the IDE is not providing immediate and constant feedback.
On the other hand for systems programming, I can't imagine what C (and even C++) could possibly do better than it except maybe compile times. Despite that, Spiral is also nothing ilke Rust - it does not try to check that pointers are safe. It is rather a extremely expressive static language that has no type annotations anywhere and looks like a dynamically typed functional language.
That's exactly how slicing a tensor works in Julia:
julia> T = copy(reshape(1:2*3*4, 2, 3, 4));
julia> summary(T)
"2×3×4 Array{Int64,3}"
julia> T[:,2,:]
2×4 Array{Int64,2}:
3 9 15 21
4 10 16 22
Inlining seems irrelevant since the slicing is done eagerly. Unless you're talking about lazy slicing, in which case you could do `f(T) = T[:,2,:]` and your inlining/function comment makes more sense. If you use StaticArrays.jl (the closest thing in Julia to Spiral's tensors) then the machine code for this operation on a 2×3×4 Float64 tensor is just: vmovups 16(%rsi), %xmm0
vmovups 64(%rsi), %xmm1
vmovups 112(%rsi), %xmm2
vmovups 160(%rsi), %xmm3
vmovups %xmm0, (%rdi)
vmovups %xmm1, 16(%rdi)
vmovups %xmm2, 32(%rdi)
vmovups %xmm3, 48(%rdi)
movq %rdi, %rax
retq
> Its type system is definitely less powerful than Spiral's - some of the things you could express naturally in Spiral would require macros in Julia.The macro comment bit is a bit perplexing since macros are about syntax and are about as unrelated to the type system as it's possible to get. I'm unaware of any way that the presence of absence of macros in a language can affect the expressiveness of its type system.
I'd be very curious to hear what can be expressed in Sprial's type system that cannot be in Julia's. Julia's type system is generally more expressive than state-of-the-art dependent static type systems since it punts on type checking entirely. This allows it to have, among other things, parametric types where the parameters can be other types, integers, floats, symbols and tuples of same (recursively).Parametric types even support fancy features like using an earlier type parameters to constrain later type parameters, e.g. `X{T<:Number, S<:Vector{<:T}}` — i.e. `T` is a possibly abstract number type and `S` is a vector whose element type is a subtype of `T`.
The only major type system feature I'm aware of Julia lacking (aside from the obvious omission of static type checking) is intersection types. There's been some thought of adding those in order to support multiple inheritance among other things, but it hasn't proven necessary yet.
I find that people often say macros are about syntax, but what they really are is some combination of a parser and a partial evaluator - in other words, their main use seems to doing compile-time function evaluation.
Spiral does not have arbitrary CTFE, but can perform any functionally-pure, non side-effecting computation in its type system plus memoization of function calls.
One thing of practical interest that makes me doubt Julia's inlining capabilities would be monads.
https://github.com/pao/Monads.jl/blob/master/doc/index.rst
"Monads.jl provides a powerful, if relatively slow"
The key word here is slow. I haven't seen a single language as of yet apart from Spiral that can inline all their overheads away.
They are pervasive in Haskell, and Haskell cannot do it. Scala wants to do it, but it can't. F# and Ocaml cannot optimize their overheads away. If Julia could then it would advertise it. This is something that is subject of academic research in the field of partial evaluation.
Speaking as a functional programmer, as a language Julia feels barely functional to me. It has first class functions, but it does not have pervasive partial application and syntax that makes such a style comfortable like functional languages tend to have. It feels more like an imperative language.
And speaking as a systems programmer, I know that without inlining guarantees you cannot have optimized functional constructs. It is not just monads. By tracking all the factions and their bodies to exactness and forgoing all heap allocation unless explicitly stated, it becomes much easier to do language interop. It is possible to make functions that capture variables from lexical scope and then pass as arguments to a function that passes them through to the GPU. Julia talks about speed, but barely talks about inlining so I am dubious about its claims.
I could go on, but I think this is a large enough sample of my views on Julia. If Julia wants me to use it, then it needs to speak more to my values as a programmer.
inl add a b = a + b
inl f = add 1
f 2, f 3
is just awesome inl add a b = a + b
is basically a macro #define add(a,b) a+b inl f = add 1
is a macro #define f add(1) f 2, f 3
but e.g. inl f = add c
would create a closure to capture c. inl would guarantee that the capturing is lexical, not dynamic.There's no need for the comma operator in args, comma is to create lists.
add:{x+y}
f:add 1
f 2
3 add = (+)
f = add 1
f 2
This kind of syntax is great for small code samples or to play in a CLI, but in larger programs more traditional (verbose) syntax works better for me. YMMV.Also, and this isn’t really an FP point, if you’ve got a lot of positional parameters you’re already Doing It Wrong.
If so, please, someone present the language from this perspective, preferably with an example.
That having said, the language is quite small and it would be possible to create a new backend in about 500 lines of code so if you really want it, you could probably do it yourself. I'd help you integrate it into the language. I know nothing about SPIRV at the moment though.