-
Notifications
You must be signed in to change notification settings - Fork 31
MandelBrot
Portalez Régis edited this page May 11, 2026
·
25 revisions
The Mandelbrot set computed on a 2D grid and saved to an image. Demonstrates:
- Splitting a
[Kernel]device function from the[EntryPoint]that drives it. - 2D thread-block / grid indexing (
threadIdx.x/threadIdx.yetc.). -
IntResidentArray— a GPU-resident buffer the runtime never copies back unless asked.
Source: src/1.Simple/Mandelbrot/Program.cs
[Kernel]
public static int IterCount(float cx, float cy)
{
int result = 0;
float x = 0.0f, y = 0.0f, xx = 0.0f, yy = 0.0f;
while (xx + yy <= 4.0f && result < maxiter)
{
xx = x * x; yy = y * y;
float xtmp = xx - yy + cx;
y = 2.0f * x * y + cy;
x = xtmp;
result++;
}
return result;
}
[EntryPoint]
public static void Run(IntResidentArray light, int lineFrom, int lineTo)
{
for (int line = lineFrom + threadIdx.y + blockDim.y * blockIdx.y; line < lineTo; line += gridDim.y * blockDim.y)
for (int j = threadIdx.x + blockIdx.x * blockDim.x; j < N; j += blockDim.x * gridDim.x)
{
float x = fromX + line * h, y = fromY + j * h;
light[line * N + j] = IterCount(x, y);
}
}The [Kernel] attribute marks IterCount as device-callable; without it, hybridizer wouldn't generate device code for that method. The [EntryPoint] wraps the host-callable kernel.
Performance discussion: hybridizer-fractal-demo-application.
1. Simple
2. Imaging
3. Maths
- Naive Matrix
- Shared Matrix
- Sparse Matrix
- Conjugate Gradient
- Newton Fractal
- Mandelbulb
- NBody
- Monte Carlo Heat Equation
4. Finance
5. CUDA Runtime
6. Advanced
- GenericFunctions
- GenericMemoryAccess
- GenericReduction
- InterfacesReduction
- LambdaReduction
- SimpleMetadataDecorator
7. AI