Skip to content

Commit

Permalink
handle uint64_t/size_t difference with configure test
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Jan 20, 2025
1 parent 68228d1 commit 22deec6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 29 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ include(cmake/build_type_helpers.cmake)
# Load other CMake helpers
include(cmake/build_helpers.cmake)
include(cmake/install_helpers.cmake)
include(cmake/compiler_features.cmake)

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
Expand Down
8 changes: 8 additions & 0 deletions cmake/compiler_features.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"#include <type_traits>
#include <cstdint>
static_assert(std::is_same<std::uint64_t, std::size_t>::value, \"INSTANTIATE_UINT64\");
int main() {}"
GKO_SIZE_T_IS_UINT64_T
FAIL_REGEX ".*INSTANTIATE_UINT64.#")
11 changes: 3 additions & 8 deletions common/unified/components/fill_array_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(GKO_DECLARE_FILL_ARRAY_KERNEL);
template GKO_DECLARE_FILL_ARRAY_KERNEL(bool);
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint16);
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint32);


// this is necessary because compilers use different types for uint64_t and
// size_t, namely unsigned long long and unsigned long
void fill_array_instantiation_helper()
{
fill_array<uint64>(nullptr, nullptr, 0, 0);
}
#ifndef GKO_SIZE_T_IS_UINT64_T
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint64);
#endif


template <typename ValueType>
Expand Down
8 changes: 3 additions & 5 deletions core/base/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ ValueType reduce_add(const array<ValueType>& input_arr,
GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(GKO_DECLARE_ARRAY_FILL);
template GKO_DECLARE_ARRAY_FILL(uint16);
template GKO_DECLARE_ARRAY_FILL(uint32);


// this is necessary because compilers use different types for uint64_t and
// size_t, namely unsigned long long and unsigned long
void array_fill_instantiation_helper(array<uint64>& a) { a.fill(0); }
#ifndef GKO_SIZE_T_IS_UINT64_T
template GKO_DECLARE_ARRAY_FILL(uint64);
#endif


#define GKO_DECLARE_ARRAY_REDUCE_ADD(_type) \
Expand Down
11 changes: 3 additions & 8 deletions core/device_hooks/common_kernels.inc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,9 @@ GKO_STUB_TEMPLATE_TYPE(GKO_DECLARE_FILL_ARRAY_KERNEL);
template GKO_DECLARE_FILL_ARRAY_KERNEL(bool);
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint16);
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint32);


// this is necessary because compilers use different types for uint64_t and
// size_t, namely unsigned long long and unsigned long
void fill_array_instantiation_helper()
{
fill_array<uint64>(nullptr, nullptr, 0, 0);
}
#ifndef GKO_SIZE_T_IS_UINT64_T
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint64);
#endif

GKO_STUB_TEMPLATE_TYPE(GKO_DECLARE_FILL_SEQ_ARRAY_KERNEL);
GKO_STUB_TEMPLATE_TYPE(GKO_DECLARE_REDUCE_ADD_ARRAY_KERNEL);
Expand Down
4 changes: 4 additions & 0 deletions include/ginkgo/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#cmakedefine GKO_HAVE_CXXABI_H


/* Is std::size_t the same type as std::uint64_t? */
#cmakedefine GKO_SIZE_T_IS_UINT64_T


/* Should we use all optimizations for Jacobi? */
#cmakedefine GINKGO_JACOBI_FULL_OPTIMIZATIONS

Expand Down
11 changes: 3 additions & 8 deletions reference/components/fill_array_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(GKO_DECLARE_FILL_ARRAY_KERNEL);
template GKO_DECLARE_FILL_ARRAY_KERNEL(bool);
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint16);
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint32);


// this is necessary because compilers use different types for uint64_t and
// size_t, namely unsigned long long and unsigned long
void fill_array_instantiation_helper()
{
fill_array<uint64>(nullptr, nullptr, 0, 0);
}
#ifndef GKO_SIZE_T_IS_UINT64_T
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint64);
#endif


template <typename ValueType>
Expand Down

0 comments on commit 22deec6

Please sign in to comment.