takagi / avm Goto Github PK
View Code? Open in Web Editor NEWEfficient and expressive arrayed vector math library with multi-threading and CUDA support in Common Lisp.
Efficient and expressive arrayed vector math library with multi-threading and CUDA support in Common Lisp.
Currently built-in functions are compiled followed by a the
form that specifies the type of return value. On the other hand, user defined functions do not come with them, it sometimes prevents their compiled forms not optimized.
We need to provide the
forms for user defined functions as well as built-in functions.
Provide ASD file to sample codes.
We introduce RSQRT built-in function that gives the reciprocal of the square root of the specified value to implement nbody sample code #4 .
For example, the reciprocal of the squre root of a float
type value x
is defined as:
(rsqrt x) = (/ 1.0 (sqrt x))
We provide RSQRT built-in function for the following types:
We need to add related definitions in the following layers:
Introduce LET* macro.
Think about the following form that set
a value to a variable foo
's element x
:
(set (float3-x foo) 0.0)
This form is compiled into the following CL form in Lisp backend:
(setf (avm.lang.data:float3-x*
(avm.lang.data:float3-values* foo0 foo1 foo2))
0.0)
Here avm.lang.data:float3-x*
is to be expanded into a multiple-value-call
form, it is not setf
able.
We need to provide setf expanders for CL-TUPLE's tuple element accessors.
We introduce DOT built-in function for the dot product operation for vector types to implement nbody sample code #4 .
For example, the dot product of two float3
vectors a = (a1, a2, a3) and b = (b1, b2, b3) is defined as:
(dot a b) = (+ (* a1 b1) (* a2 b2) (* a3 b3))
We provide the DOT built-in function for the following vector types:
We need to add related definitions in the following layers:
There are some approaches to support implicit progn in let
, flet
and labels
forms.
progn
macroconvert-implicit-progn
progn
syntaxlet
formsprogn
syntaxProvide expand-macro
and expand-macro-1
API functions which expand a macro form. expand-macro
function here is not the same as expand-macro
function in compiling phase.
Introduce *number-of-threads*
special variable that specifies how many threads are used on executing kernel functions. At the same time, *use-thread-p*
special variables are to be depricated.
Same condition on all:
debugger invoked on a SIMPLE-ERROR in thread
#<THREAD "main thread" RUNNING {1002ACC683}>:
The function COERCE is undefined.
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
(CL-CUDA.LANG.BUILT-IN::INFERRED-FUNCTION-CANDIDATES COERCE)
When running on CPU all is fine.
Introduce PROGN macro.
Currently free variables in lexical functions are not allowed so we have to pass variables we want to use in a lexical function as its arguments.
(defkernel mandelbrot (xs)
(labels ((aux (x y a b m)
(if (< m 100)
(let ((x1 (- (* x x) (* y y) a))
(y1 (- (* 2.0 x y) b)))
(if (> (+ (* x1 x1) (* y1 y1)) 4.0)
m
(aux x1 y1 a b (+ m 1))))
0)))
(let ((a (/ (coerce (- (mod i 2048) 512)) 1024.0))
(b (/ (coerce (- (/ i 2048) 1024)) 1024.0)))
(set (aref xs i) (aux 0.0 0.0 a b 1)))))
It is convenient if lexical functions accept free variables so that we do not have to pass them explicitly as following:
(defkernel mandelbrot (xs)
(let ((a (/ (coerce (- (mod i 2048) 512)) 1024.0))
(b (/ (coerce (- (/ i 2048) 1024)) 1024.0)))
(labels ((aux (x y m)
(if (< m 100)
(let ((x1 (- (* x x) (* y y) a))
(y1 (- (* 2.0 x y) b)))
(if (> (+ (* x1 x1) (* y1 y1)) 4.0)
m
(aux x1 y1 a b (+ m 1))))
0)))
(set (aref xs i) (aux 0.0 0.0 1)))))
There are several levels to support free variables. Simplest is to pass such variables as arguments implicitly by compiler, which allows us to use copy of the values. We can not modify the original values.
Item | Test | Implementation |
---|---|---|
compile-function | □ | ■ |
compile-form | □ | ■ |
compile-literal | □ | ■ |
compile-reference | □ | ■ |
compile-accessor | □ | ■ |
compile-the | □ | ■ |
compile-if | □ | ■ |
compile-let | ■ | ■ |
compile-flet | ■ | ■ |
compile-labels | ■ | ■ |
compile-set | □ | ■ |
compile-apply | □ | ■ |
lang.lisp | □ | ■ |
varenv | □ | ■ |
Implement nbody sample code.
Fix tests for CUDA backend compilation.
Currently AVM provides SET form for destructive assignment. Change it to SETF form for conventional reason.
Support macro expansion.
Currently, lexical functions for CUDA backend are compiled into individual CL-CUDA kernel functions with their names numbered as %AUX0, %AUX1, ... in the following case:
(defkernel foo ()
(flet ((aux () 1))
(aux))
=>
(cl-cuda:defkernel %aux0 (cl-cuda:int ())
(return 1))
This causes a problem that new CL-CUDA kernel functions are defined every time DEFKERNEL form is compiled, leaving out-dated useless CL-CUDA kernel definitions.
Changing lexical function names to be prefixed with outer functions' names will solve this problem.
(defkernel foo ()
(flet ((aux () 1))
(aux))
=>
(cl-cuda:defkernel %foo-aux (cl-cuda:int ())
(return 1))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.