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 agree that functions are simpler from a compiler and execution perspective.
But I think there is a difference between "simple to execute" and "simple to express complex systems".
At the machine level, binary instructions are even simpler than functions, but we don't write large systems directly in binary. We build abstractions to describe complex problems.
Object-oriented programming is one way to model complex stateful systems. It is not necessarily the best representation for every GPU kernel, but many real systems (AI frameworks, runtimes, compilers, etc.) are naturally stateful.
The question AET explores is not "are objects faster than functions?". The compiler will eventually lower higher-level abstractions into efficient execution models.
The question is: can a compiler preserve useful abstractions while still generating efficient heterogeneous code?