diff --git a/CMakeLists.txt b/CMakeLists.txt index ce9047e..62cffb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,13 @@ endif() find_package(Torch REQUIRED) +# Generate configuration header +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/csrc/include/torchfort_config.h.in + ${CMAKE_BINARY_DIR}/include/torchfort_config.h + @ONLY +) + # yaml-cpp #find_package(yaml-cpp REQUIRED) find_path(YAML_CPP_INCLUDE_DIR REQUIRED @@ -170,6 +177,7 @@ target_include_directories(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/csrc/include PUBLIC $ + $ $ ) target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES}) @@ -209,6 +217,12 @@ install( INCLUDES DESTINATION ${CMAKE_INSTALL_PREFIX}/include ) +# Install generated configuration header +install( + FILES ${CMAKE_BINARY_DIR}/include/torchfort_config.h + DESTINATION ${CMAKE_INSTALL_PREFIX}/include +) + # Fortran library and module if (TORCHFORT_BUILD_FORTRAN) diff --git a/src/csrc/include/torchfort.h b/src/csrc/include/torchfort.h index c7efdbe..fa14b11 100644 --- a/src/csrc/include/torchfort.h +++ b/src/csrc/include/torchfort.h @@ -16,8 +16,9 @@ */ #pragma once +#include "torchfort_config.h" #include -#ifdef ENABLE_GPU +#if TORCHFORT_ENABLE_GPU #include #else typedef void* cudaStream_t; diff --git a/src/csrc/include/torchfort_config.h.in b/src/csrc/include/torchfort_config.h.in new file mode 100644 index 0000000..da71958 --- /dev/null +++ b/src/csrc/include/torchfort_config.h.in @@ -0,0 +1,22 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * http://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. + */ + +#pragma once + +/* Define to 1 if TorchFort was built with GPU support */ +#cmakedefine01 TORCHFORT_ENABLE_GPU + diff --git a/src/csrc/include/torchfort_rl.h b/src/csrc/include/torchfort_rl.h index c30fcef..bb33c1c 100644 --- a/src/csrc/include/torchfort_rl.h +++ b/src/csrc/include/torchfort_rl.h @@ -16,8 +16,9 @@ */ #pragma once +#include "torchfort_config.h" #include "torchfort_enums.h" -#ifdef ENABLE_GPU +#if TORCHFORT_ENABLE_GPU #include #else typedef void* cudaStream_t;