r/Compilers • • 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 = 1

Object 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

AET-CNN:
https://github.com/onlineaet/aet-cnn

0 Upvotes

14 comments sorted by

View all comments

Show parent comment

2

u/Karyo_Ten Jun 23 '26

You're now serving me marketing slop. You said

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.

You want to introduce object-oriented programming on the GPU. Since you thought about these problems, I'm curious what you would implement as OOP in all those 3 domains: AI framework, runtimes, compilers.

1

u/General_Purple3060 Jun 23 '26

There is a misunderstanding about AET's goal.

AET is not a new GPU object-oriented programming model. It is a GCC-based compiler.

AET keeps compatibility with C syntax and extends the language with OO features. The compiler can understand object-oriented code, and a kernel defined inside an object method can be lowered into GPU target code such as PTX (and potentially other backends like GCN/SPIR-V in the future).

The main work of AET is this compilation process:

source code → compiler analysis/lowering → heterogeneous target code

The best way to understand it is to look at the implementation. You are welcome to download AET from GitHub and try it yourself.

2

u/Karyo_Ten Jun 23 '26

You keep dodging the question. Give me examples from AI inference, runtime and compiler where object-oriented code brings actual value. The best way to understand is seeing an example from you the creator about how it's meant to be used, the implementation doesn't really matter.