3.3.2.2 : Le CMakeLists.txt

Écrivons le fichier CMakeLists.txt :

Récupérons tous les fichier sources d'un coup (même si il n'y en a qu'un) :
1
file(GLOB hadamard_product_cuda_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.c" "${CMAKE_CURRENT_SOURCE_DIR}/*.cu")


Définissons un compilateur (vous pouvez changer la version, mais n'utilisez pas un compilateur trop vieux) :
1
set(CUDA_HOST_COMPILER ${CMAKE_C_COMPILER})


Ensuite, nous pouvons préciser les computes capabilities que nous voulons (en ce qui me concerne, mais Quadro M2200 est en compute capabilities 5) :
1
2
3
4
5
set(CUDA_NVCC_FLAGS
			-gencode arch=compute_50,code=sm_50
			-gencode arch=compute_60,code=sm_60
			-gencode arch=compute_80,code=sm_80
)


Enfin, nous créons notre bibliothèque :
1
cuda_add_library(hadamard_product_cuda SHARED ${hadamard_product_cuda_SRC})


Et lions la à notre bibliothèque asterics_hpc_cuda :
1
target_link_libraries(hadamard_product_cuda asterics_hpc_cuda ${CUDA_LIBRARIES})


Le fichier CMakeLists.txt complet.

1
2
3
4
5
6
7
8
9
10
file(GLOB hadamard_product_cuda_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.c" "${CMAKE_CURRENT_SOURCE_DIR}/*.cu")

set(CUDA_HOST_COMPILER ${CMAKE_C_COMPILER})
set(CUDA_NVCC_FLAGS
			-gencode arch=compute_50,code=sm_50
			-gencode arch=compute_60,code=sm_60
			-gencode arch=compute_80,code=sm_80
)
cuda_add_library(hadamard_product_cuda SHARED ${hadamard_product_cuda_SRC})
target_link_libraries(hadamard_product_cuda asterics_hpc_cuda ${CUDA_LIBRARIES})


Vous pouvez télécharger le fichier ici.