nnl 0.1.6

A high-performance neural network library for Rust with CPU and GPU support
Documentation
#version 450

// Sigmoid activation compute shader
// Computes: result[i] = 1.0 / (1.0 + exp(-input[i]))

layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;

layout(set = 0, binding = 0) buffer InputBuffer {
    float input_data[];
};

layout(set = 0, binding = 1) buffer OutputBuffer {
    float result[];
};

void main() {
    uint index = gl_GlobalInvocationID.x;

    // Bounds checking
    if (index >= input_data.length() || index >= result.length()) {
        return;
    }

    // Perform sigmoid activation entirely on GPU
    // Sigmoid(x) = 1 / (1 + e^(-x))
    // Use numerically stable implementation to avoid overflow
    float x = input_data[index];

    if (x >= 0.0) {
        float exp_neg_x = exp(-x);
        result[index] = 1.0 / (1.0 + exp_neg_x);
    } else {
        float exp_x = exp(x);
        result[index] = exp_x / (1.0 + exp_x);
    }
}