Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 2d728cc

Browse files
nicolasvasilacheftynse
authored andcommitted
Add tc_config.h.in
1 parent dcf4d83 commit 2d728cc

File tree

7 files changed

+62
-19
lines changed

7 files changed

+62
-19
lines changed

CMakeLists.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ if(WITH_CUDA)
139139
find_package(CUDA REQUIRED)
140140
include_directories(BEFORE ${CUDA_TOOLKIT_ROOT_DIR}/include)
141141

142-
# modified CUB
143-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_CUDA -DCUDA_HOME=\"\\\"${CUDA_INCLUDE_DIRS}\\\"\" -DCUB_HOME=\"\\\"${CUB_INSTALL_DIR}\\\"\" ")
144-
145142
# Inherited from Torch, see
146143
# https://github.com/torch/cutorch/blob/master/lib/THC/cmake/select_compute_arch.cmake
147144
INCLUDE(cmake/select_compute_arch.cmake)
@@ -259,6 +256,18 @@ include(cmake/GetGitRevisionDescription.cmake)
259256
################################################################################
260257
# Finally, build
261258
################################################################################
259+
# Variables for tc_config.h.in
260+
set(TC_DIR ${TC_DIR})
261+
if (WITH_CUDA)
262+
# CUDA-specific variables for tc_config.h.in
263+
set(TC_WITH_CUDA 1)
264+
set(TC_CUB_INCLUDE_DIR ${CUB_INSTALL_DIR})
265+
set(TC_CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR})
266+
set(TC_CUDA_INCLUDE_DIR ${CUDA_INCLUDE_DIRS})
267+
else()
268+
set(TC_WITH_CUDA 0)
269+
endif()
270+
configure_file("tc/tc_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/tc/tc_config.h")
262271

263272
################################################################################
264273
# Compile flags
@@ -281,13 +290,12 @@ elseif(${CMAKE_BUILD_TYPE} MATCHES "Release")
281290
endif()
282291
message(STATUS "CMAKE_INSTALL_PREFIX is ${CMAKE_INSTALL_PREFIX}")
283292

284-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTC_DIR=\"\\\"${TC_DIR}\\\"\" ")
285-
286293
include_directories(BEFORE ${PROJECT_SOURCE_DIR})
294+
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
287295
add_subdirectory(tc)
288296

289297
# At the moment pybind is only supported in CUDA mode and compilation fails
290-
# for non-CUDA mode (CUDA_HOME and CUB_HOME undefined error).
298+
# for non-CUDA mode (CUDA_INCLUDE_DIR and CUB_INCLUDE_DIR undefined error).
291299
# Once the core CPU mapper is stabilized we can worry about pybind, deactivate
292300
# conditionally for now
293301
if (WITH_CUDA)

tc/core/cuda/cuda.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
*/
1616
#pragma once
1717

18-
#ifndef CUDA_HOME
19-
#error "CUDA_HOME must be defined"
20-
#endif // CUDA_HOME
18+
#include "tc/tc_config.h"
2119

22-
#ifndef CUB_HOME
23-
#error "CUB_HOME must be defined"
24-
#endif // CUB_HOME
20+
#ifndef TC_CUDA_INCLUDE_DIR
21+
#error "TC_CUDA_INCLUDE_DIR must be defined"
22+
#endif // TC_CUDA_INCLUDE_DIR
23+
24+
#ifndef TC_CUB_INCLUDE_DIR
25+
#error "TC_CUB_INCLUDE_DIR must be defined"
26+
#endif // TC_CUB_INCLUDE_DIR
2527

2628
#include <sstream>
2729
#include <stdexcept>

tc/core/cuda/cuda_rtc.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ std::unique_ptr<CudaRTCFunction> CudaRTCFunction::Compile(
9191

9292
// Compile the program.
9393
const char* nvrtc_debug_opts[] = {"-G", "-lineinfo"};
94-
std::string cudaHome = std::string("-I ") + std::string(CUDA_HOME);
95-
std::string cubHome = std::string("-I ") + std::string(CUB_HOME);
94+
std::string cudaHome =
95+
std::string("-I ") + std::string(TC_STRINGIFY(TC_CUDA_INCLUDE_DIR));
96+
std::string cubHome =
97+
std::string("-I ") + std::string(TC_STRINGIFY(TC_CUB_INCLUDE_DIR));
9698
std::vector<const char*> nvrtcts = {arch.c_str(),
9799
"--use_fast_math",
98100
"-std=c++11",

tc/core/gpu.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
#pragma once
1717

18+
#include "tc/tc_config.h"
19+
1820
// Conditionally include CUDA-specific headers. This file should compile even
1921
// without them.
20-
#if defined(CUDA_HOME)
22+
#if TC_WITH_CUDA
2123
#include "tc/core/cuda/cuda.h"
2224
#endif
2325

@@ -27,7 +29,7 @@ namespace tc {
2729
/// The call is forwarded to the appropriate GPU driver (CUDA in particular).
2830
/// If a thread has no associated GPU device, return 0.
2931
inline size_t querySharedMemorySize() {
30-
#if defined(CUDA_HOME) && !defined(NO_CUDA_SDK)
32+
#if TC_WITH_CUDA && !defined(NO_CUDA_SDK)
3133
return CudaGPUInfo::GPUInfo().SharedMemorySize();
3234
#else
3335
return 0;

tc/tc_config.h.in

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2017-present, Facebook, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#pragma once
17+
18+
#define TC_STRINGIFY_INNER(s) #s
19+
#define TC_STRINGIFY(s) TC_STRINGIFY_INNER(s)
20+
21+
// clang-format off
22+
#define TC_DIR @TC_DIR@
23+
#define TC_WITH_CUDA @TC_WITH_CUDA@
24+
#define TC_CUDA_TOOLKIT_ROOT_DIR @TC_CUDA_TOOLKIT_ROOT_DIR@
25+
#define TC_CUDA_INCLUDE_DIR @TC_CUDA_INCLUDE_DIR@
26+
#define TC_CUB_INCLUDE_DIR @TC_CUB_INCLUDE_DIR@
27+
// clang-format on

test/cuda/test_basic_gpu.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ std::vector<char> jitCompile(
5151
std::string arch = arch_param.str();
5252

5353
// Compile the program.
54-
std::string cudaHome = std::string("-I ") + std::string(CUDA_HOME);
54+
std::string cudaHome =
55+
std::string("-I ") + std::string(TC_STRINGIFY(TC_CUDA_INCLUDE_DIR));
5556
std::vector<const char*> nvrtcts = {arch.c_str(),
5657
"--use_fast_math",
5758
"-std=c++11",
@@ -116,7 +117,7 @@ __global__ void foo(int N)
116117
}
117118

118119
TEST(BasicGpuTest, CubReduce) {
119-
std::string path(CUB_HOME);
120+
std::string path(TC_STRINGIFY(TC_CUB_INCLUDE_DIR));
120121
std::string include = std::string("-I ") + path;
121122
auto PTX = jitCompile(
122123
R"CUDA(

test/test_lang.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "tc/lang/parser.h"
2727
#include "tc/lang/sema.h"
2828
#include "tc/lang/tc_format.h"
29+
#include "tc/tc_config.h"
2930

3031
using namespace lang;
3132

@@ -34,7 +35,7 @@ using namespace lang;
3435
#endif
3536

3637
const std::string expected_file_path =
37-
std::string(TC_DIR) + "/tc/lang/test_expected/";
38+
std::string(TC_STRINGIFY(TC_DIR)) + "/tc/lang/test_expected/";
3839

3940
static inline void barf(const char* fmt, ...) {
4041
char msg[2048];

0 commit comments

Comments
 (0)