Skip to content

Commit

Permalink
Explicit check build flag (#3371)
Browse files Browse the repository at this point in the history
Adding a build option `--explicit-error-check` in setup.py along with
related changes in CMakeLists.txt, so that the python option would set a
compile option `NVFUSER_EXPLICIT_ERROR_CHECK` to the project.

This is to be used in our CI runs, where debug build is too slow but we
still want things like dynamic_cast to catch errors.

Currently the change enables some runtime check, e.g. dynamic_cast,
which was not checked previously in release build and have been hidden
in CI.
  • Loading branch information
jjsjann123 authored Nov 7, 2024
1 parent e072c92 commit 5a603db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ set(NVFUSER_SRCS_DIR "${NVFUSER_ROOT}/csrc")
set(NVFUSER_THIRD_PARTY_DIR "${NVFUSER_ROOT}/third_party")

option(NVFUSER_STANDALONE_BUILD_WITH_UCC "" OFF)
option(NVFUSER_EXPLICIT_ERROR_CHECK "" OFF)
if (NVFUSER_EXPLICIT_ERROR_CHECK)
add_compile_definitions(NVFUSER_EXPLICIT_ERROR_CHECK)
endif()
option(NVFUSER_BUILD_WITH_ASAN "Build nvFuser with asan" OFF)

include(CMakeDependentOption)
Expand Down
12 changes: 6 additions & 6 deletions csrc/disjoint_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,25 @@ class VectorOfUniqueEntries {

// Returns first element in vector
T front() const {
#ifndef NDEBUG
#if defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
NVF_ERROR(!empty());
#endif // NDEBUG
#endif // defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
return vector_.front();
}

// Returns last element in vector
T back() const {
#ifndef NDEBUG
#if defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
NVF_ERROR(!empty());
#endif // NDEBUG
#endif // defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
return vector_.back();
}

// Remove and returns the last element in vector
T popBack() {
#ifndef NDEBUG
#if defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
NVF_ERROR(!empty());
#endif // NDEBUG
#endif // defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
T v = vector_.back();
set_.erase(v);
vector_.pop_back();
Expand Down
8 changes: 4 additions & 4 deletions csrc/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ class PolymorphicBase {
// (checked in DEBUG builds)
template <class T>
T* as() {
#ifdef NDEBUG
#if defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_ERROR_CHECK)
auto downcast_ptr = static_cast<T*>(this);
#else
auto downcast_ptr = dynamic_cast<T*>(this);
NVF_ERROR(downcast_ptr != nullptr);
#endif
#endif // defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_ERROR_CHECK)
return downcast_ptr;
}

template <class T>
const T* as() const {
#ifdef NDEBUG
#if defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_ERROR_CHECK)
auto downcast_ptr = static_cast<const T*>(this);
#else
auto downcast_ptr = dynamic_cast<const T*>(this);
NVF_ERROR(downcast_ptr != nullptr);
#endif
#endif // defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_ERROR_CHECK)
return downcast_ptr;
}

Expand Down
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
BUILD_WITH_ASAN = False
BUILD_WITHOUT_DISTRIBUTED = False
OVERWRITE_VERSION = False
EXPLICIT_ERROR_CHECK = False
VERSION_TAG = None
BUILD_TYPE = "Release"
WHEEL_NAME = "nvfuser"
Expand Down Expand Up @@ -107,6 +108,9 @@
if arg == "--build-with-ucc":
BUILD_WITH_UCC = True
continue
if arg == "--explicit-error-check":
EXPLICIT_ERROR_CHECK = True
continue
if arg == "--build-with-asan":
BUILD_WITH_ASAN = True
continue
Expand Down Expand Up @@ -330,6 +334,8 @@ def cmake():
]
if BUILD_WITH_UCC:
cmd_str.append("-DNVFUSER_STANDALONE_BUILD_WITH_UCC=ON")
if EXPLICIT_ERROR_CHECK:
cmd_str.append("-DNVFUSER_EXPLICIT_ERROR_CHECK=ON")
if not NO_NINJA:
cmd_str.append("-G")
cmd_str.append("Ninja")
Expand Down

0 comments on commit 5a603db

Please sign in to comment.