#![cfg_attr(target_arch = "nvptx64", no_std)]
#![cfg_attr(target_arch = "nvptx64", feature(abi_ptx))]

use cuda_std::prelude::*;

/// Scales each element: data[i] *= scale
#[kernel]
#[allow(improper_ctypes_definitions)]
pub unsafe fn scale_array(data: *mut f32, len: u32, scale: f32) {
    let idx = thread::index_1d() as u32;
    if idx >= len {
        return;
    }

    let ptr = unsafe { data.add(idx as usize) };
    *ptr = *ptr * scale;
}

/// Adds two arrays: c[i] = a[i] + b[i]
#[kernel]
#[allow(improper_ctypes_definitions)]
pub unsafe fn add_arrays(a: *const f32, b: *const f32, c: *mut f32, len: u32) {
    let idx = thread::index_1d() as u32;
    if idx >= len {
        return;
    }

    let i = idx as usize;
    *c.add(i) = *a.add(i) + *b.add(i);
}
