Git Product home page Git Product logo

chapelcl's People

Contributors

louisjenkinscs avatar

Stargazers

 avatar

Watchers

 avatar

chapelcl's Issues

Backdoor - Raw String Expressions

var kernel = new GPUKernel();
var x = kernel.createScalar("x", GPUVariableType.INT);
kernel.createCustomStmt(x.name + " = pow(random(), 2) % 3");

Something like the above can be used for when things get so complicated that you cannot actually rely on what we provide. It follows the 'multiresolution design philosophy' too!

Specification of Chapel -> AST -> OpenCL

ChapelCL Specification

This document will be a placeholder for an official specification that will be followed when designing this library, and should provide a high-level description of the end-to-end compilation from Chapel symbolic variables, expressions, and statements down to OpenCL.

Symbolic Variables

In Chapel, we provide what are referred to as 'symbolic' variables, in that they do not hold a concrete value, but more or less function as 'names' that you can create entire expressions and statements out of. For an example of a symbolic variable, think of some variable x that you want to increment, x += 1. The actual value of x is not known until you run the program, as only then does it hold some concrete value. These symbolic variables are not concerned with what value x holds before and after the increment, just that some variable x gets incremented.

TODO: Discuss benefits and limitations, as well as code snippet

Scalars

TODO: Discuss Scalars

Arrays

TODO: Discuss Vectors

Symbolic Loops

var arr; // TODO: Finalize design on how to create symbolic arrays
for a in arr {
   // ...
}
var arr; // TODO: Finalize design on how to create symbolic arrays
forall a in arr {
   // ...
}

Symbolic Variables to AST

TODO: Describe how we map down Chapel-idiomatic code to an AST

AST to OpenCL/CUDA/Metal/etc. GPU Kernel

TODO: Describe how we map down AST to GPU kernel

Add names for global id, local id, etc.

To introduce parallelism, things like 'get_global_idandget_local_id`, etc., should be cached into some variable, or at least abstractly represented via some symbolic variable.

Variable Creation

Support creating GPUVariable of various types that match what the backend requires.

// Anonymous typed variable
var x : GPUVariable(int);
var y : GPUVariable(real);
// Named typed variables
var z : GPUVariable(int, name="z");
var arr : GPUArray(int, {1..10});

Comparison to AMD Effort - HSA Chapel

Examples of programs can help to determine how I should structure/create my own library.

Helper kernels written in C can help provide insight on what kernels I should provide (they should be generated in my own library but available for composition to the user)

Layouts like these can be somewhat useful to look at.

Interesting stuff.

Represent Operations as an AST

It might be wiser to construct the AST on-the-fly, as then we do not need to store stringified output until we want to actually write it all out into the GPU kernel. It could be pretty interesting...

proc +(sym1 : GPUVariable, obj) {
   // Initializer overloaded to take certain supported types
   // Maybe even other GPUInstr types?
   return GPUAddInstr(sym1, obj);
}

Could be rather promising, at the very least, for providing a framework for creating DSLs that allow you to make use of a high-level language like Chapel!

Array Slicing

Slicing an array can be represented via overloading this to take a range which can return a symbolic array view. This can work to support strided arrays as well!

Code Snippets to use for later

Obtaining ideal workgroup size

size_t sz;
size_t retsz;
clGetKernelWorkGroupInfo(kernel, device_id,  CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, sizeof(sz), &sz, &retsz);

Conditionals on Symbolic Variables

One big issue I can foresee if in the application of conditionals. For example...

var kernel = new GPUKernel();
var x = kernel.createScalar("x", GPUVariableType.INT);
var y = kernel.createScalar("y", GPUVariableType.INT);
var arr = kernel.createArray("arr", GPUVariableType.INT, 10);
for a in arr do a = if x > y then x else y;

The above clearly will not work. Why? Because how do we compare two variables without concrete values? We can only really generate the code we execute, and the goal is to not rely on the compiler for this kind of stuff.

I propose that instead of trying to figure out how to make this implicit, I can create an API to make this more explicit.

var kernel = new GPUKernel();
var x = kernel.createScalar("x", GPUVariableType.INT);
var y = kernel.createScalar("y", GPUVariableType.INT);
var arr = kernel.createArray("arr", GPUVariableType.INT, 10);
for a in arr {
   var cond = kernel.createIfStmt(x > y);
   cond.beginIfTrue();
   a = x;
   cond.beginFalse(); 
   a = y;
   cond.done();
};

I know, its not as cool-looking, but it would work. As well if we had better first-class function support, we'd have kernel.creatIfStmt(x > y, lambda () { a = x; }, lambda () { a = y; }).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.