The framework provides a simple and intuitive API, primarily exposed through the lskel::Vector class. Review the constructors, core operations, and utility functions below.
The lskel::Vector class offers a variety of constructors for seamless initialization from different data sources, including standard C++ vectors or other lskel::Vector objects. This flexibility allows developers to easily move their data to the GPU and begin computation. In the table below are the ways to initialize our Vector.
| API | Brief description |
|---|---|
lskel::Vector<T> vector(N) |
Initializes vector of type T with size N |
lskel::Vector<T> vector(N, x) |
Initializes vector of type T with size N, with all values equal to x |
lskel::Vector<T> vector(std::vector v) |
Initializes a vector with the contents of the standard vector v |
lskel::Vector<T> vector(lskel::vector v) |
Initializes a vector with the contents of another vector from our framework |
These functions are the core functions for performing parallel computations. The operations are designed to be chainable, returning a new expression object that represents the pending computation. The computation is only executed when the expression is assigned to a variable or read operations (.print() and accessing through the [] operator), triggering the lazy evaluation model.
| API | Brief description |
|---|---|
vector.map(op) |
Applies op to every element in vector. |
vector.map(in, op) |
Applies an operation op with an extra input in, to every element in vector. |
vector.map(in, op, out1, out2) |
Applies an operation op with vector and in as inputs and returns the desired output to out1 and out2. The operation must return a Pair struct. Calling this ends the chain. |
vector.map(op, out) |
Applies an operation op with vector as input and returns the result to out. |
vector.map(in, op, out) |
Applies an operation op with vector and in as input and return the result to out. |
vector.reduce(op, i) |
Transforms a Vector with an operation op and identity i, into a reduced, single value. Calling this ends the chain. |
In the snippet below, we illustrate our frameworkâs chaining mechanism. First, op1 is applied to vec, with the result stored in out1. Then, the composition of op2 and op3 is executed as a single fused operation, and the final result is stored in out2.
vec.map(op1, out1).map(op2).map(op3,out2)
This set of functions provides helpful utilities for managing data transfers, debugging, and inspecting the contents of the vector. While some of these are intended for development and debugging, they are essential tools for ensuring the correctness of the program.
| API | Brief description |
|---|---|
vector[i] |
Access of the data of the vector, depending on context it could be device or host data. |
vector.copyToHost(std::vector<T> v) |
Copies the device data to a standard vector v. |
vector.copyToHost(std::vector<T>& v, cudaStream_t s) |
Used for debugging. Copies the device data asynchronously to a standard vector v. |
vector.copyToDeviceAsync(std::vector<T>& v) |
Copies the contents of a standard vector v to the vector's device data. |
vector.synchronize() |
Used for debugging, Synchronizes the vector's stream. |
vector.fill_with_sequence() |
Fills all the vector's elements with the value index + 1. |
vector.print(char* msg) |
Prints the string msg and then prints the contents of the vector. |