r/Compilers • u/General_Purple3060 • Jun 22 '26
AET: Turning an Object Method into a GPU Kernel - Exploring Object-Oriented Heterogeneous Programming
I recently introduced AET, a GCC-based compiler/language project exploring heterogeneous computing.
This post shows a small example: how an object method can become a GPU kernel.
The motivation is simple:
Traditional CUDA programming separates:
- C++ host code
- CUDA kernels
- GPU memory management
For example, an object containing both state and behavior usually needs to be manually split between CPU objects and GPU data.
AET explores another direction:
A simple GPU kernel in AET
AET introduces class$ and impl$ to describe classes, while supporting GPU annotations like __global__ and __device__.
Example:
#include <stdio.h>
class$ HelloGPU
{
__global__ void hello();
};
impl$ HelloGPU
{
__global__ void hello()
{
printf("hello world from GPU\n");
int id = threadIdx.x;
printf("thread id = %d\n", id);
}
};
int main()
{
HelloGPU *gpu = new$ HelloGPU();
gpu->hello<<<1,2>>>();
MtcsSystem.synchronize();
}
The compiler generates NVIDIA PTX:
.visible .entry _Z8HelloGPU5helloEPN8HelloGPUE
{
...
}Runtime:
hello world from GPU
hello world from GPU
thread id = 0
thread id = 1Object model across CPU/GPU
The more interesting part is not the kernel itself.
The question is:
How can an object cross the CPU/GPU execution boundary?
In AET:
Object *a = new$ Object();the compiler analyzes whether the object participates in heterogeneous execution.
- Normal objects use regular CPU heap allocation.
- Heterogeneous objects use device-accessible memory.
- CUDA backend currently uses Unified Memory.
The goal is to allow GPU code to access object state naturally:
class$ HelloGPU
{
int value;
__global__ void hello();
};
impl$ HelloGPU
{
__global__
void hello()
{
printf("%d\n", self->value);
}
};self represents the object inside GPU execution.
There are still limitations.
A GPU kernel cannot call normal CPU methods because they are compiled into different execution spaces.
Example:
class$ Test
{
void cpuFunction();
__device__
void gpuFunction()
{
cpuFunction(); // not allowed
}
};AET is still an experimental project.
The current focus areas are:
- object lifetime management across devices
- CPU/GPU state synchronization
- automatic execution placement
The source code and experiments:
AET compiler:
https://github.com/onlineaet/aet
View all comments
Show parent comment
4
u/Karyo_Ten Jun 22 '26
Have you looked at what part of AI framework is stateful?
And what do you put behind "runtime"?
What compiler phase can run on GPU faster than on CPU?
In the presence of mutation, if only just pointer aliasing, the compiler has to be conservative and disable optimization. Mutable state will hinder performance.
Functions are a useful abstraction and can already today be used on host and device and composed into more complex functions even through higher-order functions and closures. And inlined/constexpr as well if they can be compiletime-folded.