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
1
u/General_Purple3060 Jun 23 '26
I think the key point may not be "OO vs functions".
A compiler is a bridge between how humans describe problems and how hardware executes them. Humans use abstractions (functions, objects, types, models, etc.), while hardware finally executes low-level instructions. The compiler's job is to lower those abstractions into efficient execution models.
Whether the source is:
(1) file → function → GPU kernel
or
(2) file → class → method → GPU kernel
the real compiler question is: can we generate efficient code after lowering?
A class can also be viewed as a structured data representation plus related functions. The existence of an extra abstraction layer does not automatically mean worse performance. Of course, naive object models can hurt optimization because of things like aliasing and dynamic behavior. This is exactly where compiler analysis and lowering strategies matter.
In AET, for example, I found that component_ref based object calls were not ideal for performance, so the compiler lowers some method calls into call_expr internally.
But the bigger goal of AET is not proving "objects are faster than functions".
The bigger goal is reducing the amount of hardware-specific programming.
Just like GCC allows developers to write code without caring whether the target is Intel, AMD, or ARM, AET explores whether GPU, TPU, NPU and other heterogeneous devices can be represented by a common abstraction layer (MTCS), then lowered by the compiler.