You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace the add/subtract demo with a more instructional example: the
Mandelbrot set rendered two ways so users can read both implementations
side by side and compare their performance.
- src/mandelbrot_cpu.cpp: plain nested loop over every pixel
- src/mandelbrot.cu: the same logic as a CUDA kernel, one thread per pixel
- src/main.cpp: shared wrapper returning a (height, width) int32 NumPy array,
releasing the GIL during compute
- both functions take identical arguments and return identical arrays
- add numpy as a runtime dependency; test GPU output matches the CPU
- ignore vim swap files
Assisted-by: ClaudeCode:claude-opus-4.8
The compiled wheel is written to `./wheelhouse/` on the host, so you can inspect
96
135
or install it afterwards. Because the container has no GPU, `cuda_available()`
97
-
returns `False` and the `add`/`subtract` tests are skipped. The same flow runs
98
-
in CI in the `cuda` job of `.github/workflows/pip.yml`.
136
+
returns `False` and the `mandelbrot_gpu` test is skipped (the `mandelbrot_cpu`
137
+
tests still run). The same flow runs in CI in the `cuda` job of
138
+
`.github/workflows/pip.yml`.
99
139
100
140
## Files
101
141
@@ -104,9 +144,10 @@ necessary. The necessary files are:
104
144
105
145
* `pyproject.toml`: The Python project file
106
146
* `CMakeLists.txt`: The CMake configuration file, which requires the CUDA language
107
-
* `src/main.cpp`: The pybind11 bindings
108
-
* `src/add.cu`: The CUDA kernels (`add`/`subtract`) and runtime device query
109
-
* `src/add.h`: The shared declarations
147
+
* `src/main.cpp`: The pybind11 bindings (turns the results into NumPy arrays)
148
+
* `src/mandelbrot_cpu.cpp`: The CPU implementation
149
+
* `src/mandelbrot.cu`: The CUDA kernel and runtime device query
150
+
* `src/mandelbrot.h`: The shared declarations
110
151
* `src/cuda_example/__init__.py`: The Python portion of the module. The root of the module needs to be `<package_name>`, `src/<package_name>`, or `python/<package_name>` to be auto-discovered.
111
152
112
153
These files are also expected and highly recommended:
@@ -148,6 +189,7 @@ terms and conditions of this license.
0 commit comments