nodepp-gpu is a proof-of-concept library that brings the power of General-Purpose GPU (GPGPU) computing to C++ and Nodepp, inspired by the popular JavaScript library gpu.js. It allows you to write C++ functions that are executed on the GPU, leveraging the parallel processing capabilities of modern graphics hardware.
This library is a part of the larger Nodepp project.
- GPU Kernel Execution: Write your computational logic in GLSL (OpenGL Shading Language) and have it executed on the GPU.
- Seamless Integration with Nodepp: Uses Nodepp's core data structures and concepts for a familiar developer experience.
- Type-Safe Data Handling: Provides a
matrix_tclass to represent and manage data, including support for various vector types (vec2,vec3,vec4,sampler2D, etc.). - Flexible Input/Output: Easily set input variables and textures for your GPU kernel and retrieve the computed result as a
matrix_tobject. - Raylib Integration: Built on top of the Raylib library for its OpenGL context management and shader capabilities.
- Image Processing: Load images from memory, file paths, or existing textures and use them as input for your GPU computations.
# raylib
π https://github.com/raysan5/raylib
# nodepp
π https://github.com/NodeppOfficial/nodepp#include <nodepp/nodepp.h>
#include <gpu/gpu.h>
using namespace nodepp;
void onMain() {
if( !gpu::start_machine() )
{ throw except_t("Failed to start GPU machine"); }
gpu::gpu_t gpu ( GPU_KERNEL(
vec2 idx = uv / vec2( 2, 2 );
float color_a = texture( image_a, idx ).x;
float color_b = texture( image_b, idx ).x;
float color_c = color_a * color_b;
return vec4( vec3( color_c ), 1. );
));
gpu::matrix_t matrix_a( 2, 2, ptr_t<float>({
10., 10.,
10., 10.,
}) );
gpu::matrix_t matrix_b( 2, 2, ptr_t<float>({
.1, .2,
.4, .3,
}) );
gpu.set_output(2, 2, gpu::OUT_DOUBLE4);
gpu.set_input (matrix_a, "image_a");
gpu.set_input (matrix_b, "image_b");
for( auto x: gpu().data() )
{ console::log(x); }
gpu::stop_machine();
}This example demonstrates how to set up the inputs, execute the kernel, and retrieve the result. The gpu_t::operator() handles the entire process of compiling the shader, rendering to a texture, and converting the texture back into a matrix_t object.
πͺ: time g++ -o main main.cpp -L./lib -I./include -lraylib -lssl -lcrypto -lws2_32 ; ./main.exe
π§: time g++ -o main main.cpp -L./lib -I./include -lraylib -lssl -lcrypto ; ./main