-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CUDA support and example in devcontainer and CMake configuration
- Loading branch information
timetravelCat
committed
Dec 8, 2024
1 parent
8790dfe
commit 65e3583
Showing
7 changed files
with
104 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ This template is designed with a primary focus on enabling individuals to set up | |
┃ ┣ 📜ExampleProjectConfig.cmake.in | ||
┃ ┣ 📜Version.h.in | ||
┃ ┣ 📜clang-tidy.cmake | ||
┃ ┣ 📜cuda.cmake | ||
┃ ┗ 📜cppcheck.cmake | ||
┣ 📦docs | ||
┃ ┣ 📜index.md | ||
|
@@ -88,7 +89,8 @@ This template is designed with a primary focus on enabling individuals to set up | |
┃ ┃ ┗ 📜Version.h | ||
┣ 📂src | ||
┃ ┣ 📜example_debug.cpp | ||
┃ ┗ 📜example_project.cpp | ||
┃ ┣ 📜example_project.cpp | ||
┃ ┗ 📜example_cuda.cu | ||
┣ 📂test | ||
┃ ┣ 📜CMakeLists.txt | ||
┃ ┗ 📜test_example.cpp | ||
|
@@ -110,6 +112,13 @@ This template is designed with a primary focus on enabling individuals to set up | |
- Rename folder name of [***include/ExampleProject***](include) | ||
- Rename [***cmake/ExampleProjectConfig.cmake.in***](cmake) | ||
|
||
3. CUDA (Optional) | ||
- Uncomment cuda features in [***devcontainer.json***](.devcontainer/devcontainer.json) | ||
|
||
4. Documentations via mkdocs (Optional) | ||
- Check **GitHub Pages** and Select **Deploy from a branch**, Branch as **gh-pages**, **/(root)**. | ||
- Check [***docs workflow***](.github/workflows/docs.yml), [***mkdocs configuration***](mkdocs.yml) | ||
|
||
--- | ||
|
||
## 📜 License | ||
|
@@ -129,7 +138,7 @@ For any inquiries or support, please contact [email protected] | |
--- | ||
|
||
## ✅ TODO | ||
- [ ] Automatically detect CUDA and CUDA hardware. | ||
- [x] Automatically detect CUDA and CUDA hardware. | ||
- [ ] ROS2 branch, for ROS2-based packages. | ||
- [x] Project documentation template (using mkdocs). | ||
- [ ] Option for direct use of Docker image including all major features. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2024 timetravelCat | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
include(CheckLanguage) | ||
check_language(CUDA) | ||
|
||
if(CMAKE_CUDA_COMPILER) | ||
enable_language(CUDA) | ||
set(CMAKE_CUDA_STANDARD 17) | ||
set(CMAKE_CUDA_STANDARD_REQUIRED ON) | ||
set(CMAKE_CUDA_SEPARABLE_COMPILATION ON) | ||
|
||
# https://developer.nvidia.com/cuda-gpus | ||
# native is available in 3.24 https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html#prop_tgt:CUDA_ARCHITECTURES | ||
set(CMAKE_CUDA_ARCHITECTURES 86) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of NVIDIA CORPORATION nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
// System includes | ||
#include <stdio.h> | ||
|
||
// CUDA runtime | ||
#include <cuda_runtime.h> | ||
|
||
__global__ void testKernel(int val) { | ||
printf("[%d, %d]:\t\tValue is:%d\n", blockIdx.y * gridDim.x + blockIdx.x, threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x, val); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
printf("printf() is called. Output:\n\n"); | ||
|
||
// Kernel configuration, where a two-dimensional grid and | ||
// three-dimensional blocks are configured. | ||
dim3 dimGrid(2, 2); | ||
dim3 dimBlock(2, 2, 2); | ||
testKernel<<<dimGrid, dimBlock>>>(10); | ||
cudaDeviceSynchronize(); | ||
|
||
return EXIT_SUCCESS; | ||
} |