Cuda et la programmation GPU non-NVidia
Bonjour tout le monde,
Je développe sur mon temps surtout en Java. Et là je voudrais porter mes bibliothèques en C++ avec l'accélération graphique CUDA.
Je compile d'abord mon hello, world qui fait simplement la somme de 2 tableaux en appelant le processeur graphique (code sur le site NVIDIA). Je rencontre des difficultés pour élaborer mon makefile:
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| cmake_minimum_required(VERSION 3.20)
set(CMAKE_CUDA_STANDARD 11)
#set(CMAKE_CUDA_INCLUDE_WHAT_YOU_USE "C:/Program~1/NVIDIA~1/CUDA/v11.4/bin")
#"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/bin"
set(CMAKE_CUDA_COMPILER "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/bin/nvcc.exe")
set(CUDAToolkit_ROOT "CC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/bin")
set(CMAKE_CUDA_ARCHITECTURES compute_52)
project(untitled2 CUDA)
#set(CMAKE_CXX_STANDARD )
add_executable(untitled2 main.cu)
set_target_properties(untitled2 PROPERTIES
CUDA_SEPARABLE_COMPILATION ON) |
Le code ne compile pas
https://pastebin.com/edY3W5jf
J'utilise la carte intégrée Intel, sur l'autre PC Windows une carte MSI GT 710. Cuda 11, CLion.:D
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include <iostream>
#include <math.h>
// Kernel function to add the elements of two arrays
__global__
void add(int n, float *x, float *y)
{
for (int i = 0; i < n; i++)
y[i] = x[i] + y[i];
}
int main(void)
{
int N = 1<<20;
float *x, *y;
// Allocate Unified Memory accessible from CPU or GPU
cudaMallocManaged(&x, N*sizeof(float));
cudaMallocManaged(&y, N*sizeof(float));
// initialize x and y arrays on the host
for (int i = 0; i < N; i++) {
x[i] = 1.0f;
y[i] = 2.0f;
}
// Run kernel on 1M elements on the GPU
add<<<1, 1>>>(N, x, y);
// Wait for GPU to finish before accessing on host
cudaDeviceSynchronize();
// Check for errors (all values should be 3.0f)
float maxError = 0.0f;
for (int i = 0; i < N; i++)
maxError = fmax(maxError, fabs(y[i]-3.0f));
std::cout << "Max error: " << maxError << std::endl;
// Free memory
cudaFree(x);
cudaFree(y);
return 0;
} |