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
0
u/General_Purple3060 Jun 22 '26
I think this is actually the key design trade-off.
One of the ideas behind AET is:
Put the complexity into the compiler, keep the user model simple.
For example:
Object *a = new$ Object();
Object b = new$ Object();
From the programmer's view, this is just object creation.
If the compiler can determine that an object is related to heterogeneous execution,
the allocation strategy can be changed automatically (device memory, unified memory, or other mechanisms depending on the backend).
The important part is that the language source is the "raw material" for the compiler.
The actual allocation mechanism does not necessarily have to live inside the compiler itself;
it can be implemented in runtime libraries or backend components.
This also keeps the compiler cleaner and allows different targets to provide different implementations.
During AET development, I have actually spent a lot of time deciding where the boundary should be between compiler and runtime/library.
That boundary is probably one of the hardest parts of designing a heterogeneous language.