20 lines
751 B
Text
20 lines
751 B
Text
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
||
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
#include <cstdint>
|
||
|
|
#include <cuda_runtime.h>
|
||
|
|
|
||
|
|
__global__ void Double(float* values, std::int32_t count) {
|
||
|
|
const std::int32_t i = static_cast<std::int32_t>(blockIdx.x * blockDim.x + threadIdx.x);
|
||
|
|
if (i < count) values[i] = 2.0f * static_cast<float>(i);
|
||
|
|
}
|
||
|
|
|
||
|
|
extern "C" std::int32_t LaunchDouble(std::int32_t count, float* values) {
|
||
|
|
float* device = nullptr;
|
||
|
|
cudaError_t status = cudaMalloc(&device, sizeof(float) * count);
|
||
|
|
if (status != cudaSuccess) return status;
|
||
|
|
Double<<<1, 32>>>(device, count);
|
||
|
|
status = cudaMemcpy(values, device, sizeof(float) * count, cudaMemcpyDeviceToHost);
|
||
|
|
cudaFree(device);
|
||
|
|
return status;
|
||
|
|
}
|