You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.
import { Program, Kernel, Global } from "std/opencl"
extern @[Kernel] void vector_add(
@[Global] const int *A,
@[Global] const int *B,
@[Global] int *C
) {
// Get the index of the current element to be processed
int i = get_global_id(0);
// Do the operation
C[i] = A[i] + B[i];
}
final program = Program()
program.run<$vector_add>(a, b, c)
Many things are omitted for brevity. However, it can be seen that Onyx annotations may be applied in C context as well, even without the need to use $ (@ is unused in C; it also allows to use Onyx intrinsics within a C context).
Passing a C function prototype as a template argument allows to lens through the prototype metadata during compilation, including annotations.
This can be also done via macros, I suppose, but a compiler is likely to implement kernel compilation natively.
Alternatively, a compiler may allow to load a pre-compiled code like program.load_kernel("mykernel.spirv").
This wouldn't allow type checking, though.
That said, OpenCL binding looks like a big chunk of problems for a compiler to stay compliant. Therefore, I think that a portion of standard library shall be considered optional. Also, OpenCL versioning...
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Imagine how https://www.eriksmistad.no/getting-started-with-opencl-and-gpu-computing could look like in Onyx:
Many things are omitted for brevity. However, it can be seen that Onyx annotations may be applied in C context as well, even without the need to use
$
(@
is unused in C; it also allows to use Onyx intrinsics within a C context).Passing a C function prototype as a template argument allows to lens through the prototype metadata during compilation, including annotations.
This can be also done via macros, I suppose, but a compiler is likely to implement kernel compilation natively.
Alternatively, a compiler may allow to load a pre-compiled code like
program.load_kernel("mykernel.spirv")
.This wouldn't allow type checking, though.
That said, OpenCL binding looks like a big chunk of problems for a compiler to stay compliant. Therefore, I think that a portion of standard library shall be considered optional. Also, OpenCL versioning...
Beta Was this translation helpful? Give feedback.
All reactions