fix building errors on FreeBSD (#105897)

Although FreeBSD is not officially supported, this PR fixes some errors on FreeBSD.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/105897
Approved by: https://github.com/kit1980
This commit is contained in:
cyy
2023-07-26 08:11:39 +00:00
committed by PyTorch MergeBot
parent afd621ddde
commit 5c5eece6d8
3 changed files with 13 additions and 13 deletions

View File

@ -40,7 +40,7 @@ namespace {
// use `cidx/idx` to refer to `compressed_indices/plain_indices` respectively.
INVARIANT_CHECK_FUNC_API
_assert(const bool cond, const char* const message) {
_torch_assert(const bool cond, const char* const message) {
#ifdef GPUCC
CUDA_KERNEL_ASSERT(cond && message);
#else
@ -58,9 +58,9 @@ INVARIANT_CHECK_FUNC_API _check_first_cidx_is_zero(
const index_t& zero) {
const bool invariant = cidx == zero;
if (cdim_name == CDimName::CRow) {
_assert(invariant, "`crow_indices[..., 0] == 0` is not satisfied.");
_torch_assert(invariant, "`crow_indices[..., 0] == 0` is not satisfied.");
} else {
_assert(invariant, "`ccol_indices[..., 0] == 0` is not satisfied.");
_torch_assert(invariant, "`ccol_indices[..., 0] == 0` is not satisfied.");
}
}
@ -72,9 +72,9 @@ INVARIANT_CHECK_FUNC_API _check_last_cidx_is_nnz(
const index_t& nnz) {
const bool invariant = cidx == nnz;
if (cdim_name == CDimName::CRow) {
_assert(invariant, "`crow_indices[..., -1] == nnz` is not satisfied.");
_torch_assert(invariant, "`crow_indices[..., -1] == nnz` is not satisfied.");
} else {
_assert(invariant, "`ccol_indices[..., -1] == nnz` is not satisfied.");
_torch_assert(invariant, "`ccol_indices[..., -1] == nnz` is not satisfied.");
}
}
@ -89,11 +89,11 @@ INVARIANT_CHECK_FUNC_API _check_cidx_nondecreasing_locally_bounded_sequence(
const auto s_cidx = cidx_next - cidx;
const bool invariant = zero <= s_cidx && s_cidx <= dim;
if (cdim_name == CDimName::CRow) {
_assert(
_torch_assert(
invariant,
"`0 <= crow_indices[..., 1:] - crow_indices[..., :-1] <= ncols` is not satisfied.");
} else {
_assert(
_torch_assert(
invariant,
"`0 <= ccol_indices[..., 1:] - ccol_indices[..., :-1] <= nrows` is not satisfied.");
}
@ -108,9 +108,9 @@ INVARIANT_CHECK_FUNC_API _check_idx_bounds(
const index_t& dim) {
const bool invariant = zero <= idx && idx < dim;
if (cdim_name == CDimName::CRow) {
_assert(invariant, "`0 <= col_indices < ncols` is not satisfied.");
_torch_assert(invariant, "`0 <= col_indices < ncols` is not satisfied.");
} else {
_assert(invariant, "`0 <= row_indices < nrows` is not satisfied.");
_torch_assert(invariant, "`0 <= row_indices < nrows` is not satisfied.");
}
}
@ -129,14 +129,14 @@ INVARIANT_CHECK_FUNC_API _check_idx_sorted_distinct_vals_slices_with_cidx(
for (auto* RESTRICT curr = slice_begin + 1; curr < slice_end; ++curr) {
const auto invariant = *(curr - 1) < *curr;
if (cdim_name == CDimName::CRow) {
_assert(
_torch_assert(
invariant,
"`col_indices[..., crow_indices[..., i - 1]:crow_indices[..., i]] "
"for all i = 1, ..., nrows "
"are sorted and distinct along the last dimension values` "
"is not satisfied.");
} else {
_assert(
_torch_assert(
invariant,
"`row_indices[..., ccol_indices[..., i - 1]:ccol_indices[..., i]] "
"for all i = 1, ..., ncols "

View File

@ -326,7 +326,7 @@ constexpr uint32_t CUDA_THREADS_PER_BLOCK_FALLBACK = 256;
// CUDA_KERNEL_ASSERT checks the assertion
// even when NDEBUG is defined. This is useful for important assertions in CUDA
// code that would otherwise be suppressed when building Release.
#if defined(__ANDROID__) || defined(__APPLE__) || \
#if defined(__ANDROID__) || defined(__APPLE__) || defined(__FreeBSD__) || \
(defined(USE_ROCM) && ROCM_VERSION < 40100)
// Those platforms do not support assert()
#define CUDA_KERNEL_ASSERT(cond)

View File

@ -34,7 +34,7 @@ TEST(ExceptionTest, TORCH_INTERNAL_ASSERT_DEBUG_ONLY) {
}
// On these platforms there's no assert
#if !defined(__ANDROID__) && !defined(__APPLE__) && \
#if !defined(__ANDROID__) && !defined(__APPLE__) && !defined(__FreeBSD__) && \
!(defined(USE_ROCM) && ROCM_VERSION < 40100)
TEST(ExceptionTest, CUDA_KERNEL_ASSERT) {
// This function always throws even in NDEBUG mode