Skip to content

Commit

Permalink
Fix the gtest issue with MSVC.
Browse files Browse the repository at this point in the history
`using T = x;` is banned inside any gtest class used in a `TYPED_TEST`
fashion because gtest also defines a `T` of its own and somehow `MSVC`
confuses the two.
  • Loading branch information
tcojean committed Oct 16, 2020
1 parent 2c97b04 commit 541ae8b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 31 deletions.
3 changes: 3 additions & 0 deletions core/test/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <type_traits>


#include <gtest/gtest.h>


#include <ginkgo/core/base/math.hpp>
#include <ginkgo/core/base/types.hpp>

Expand Down
2 changes: 1 addition & 1 deletion include/ginkgo/core/base/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ class Executor : public log::EnableLogging<Executor> {
try {
this->raw_copy_from(src_exec, num_elems * sizeof(T), src_ptr,
dest_ptr);
} catch (NotSupported &err) {
} catch (NotSupported &) {
// Unoptimized copy. Try to go through the masters.
auto src_master = src_exec->get_master().get();
if (num_elems > 0 && src_master != src_exec) {
Expand Down
16 changes: 8 additions & 8 deletions include/ginkgo/core/base/lin_op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,12 @@ using EnableDefaultLinOpFactory =
*
* @ingroup LinOp
*/
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name) \
public: \
class _factory_name; \
struct _parameters_name##_type \
: ::gko::enable_parameters_type<_parameters_name##_type, \
_factory_name>
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name) \
public: \
class _factory_name; \
struct _parameters_name##_type \
: public ::gko::enable_parameters_type<_parameters_name##_type, \
_factory_name>


/**
Expand Down Expand Up @@ -905,8 +905,8 @@ public: \
_parameters_name##_type> { \
friend class ::gko::EnablePolymorphicObject<_factory_name, \
::gko::LinOpFactory>; \
friend class ::gko::enable_parameters_type<_parameters_name##_type, \
_factory_name>; \
friend struct ::gko::enable_parameters_type<_parameters_name##_type, \
_factory_name>; \
explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec) \
: ::gko::EnableDefaultLinOpFactory<_factory_name, _lin_op, \
_parameters_name##_type>( \
Expand Down
16 changes: 8 additions & 8 deletions include/ginkgo/core/matrix/csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,22 +437,22 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
{
if (warp_size_ > 0) {
int multiple = 8;
if (nnz >= 2e8) {
if (nnz >= static_cast<int64_t>(2e8)) {
multiple = 2048;
} else if (nnz >= 2e7) {
} else if (nnz >= static_cast<int64_t>(2e7)) {
multiple = 512;
} else if (nnz >= 2e6) {
} else if (nnz >= static_cast<int64_t>(2e6)) {
multiple = 128;
} else if (nnz >= 2e5) {
} else if (nnz >= static_cast<int64_t>(2e5)) {
multiple = 32;
}

#if GINKGO_HIP_PLATFORM_HCC
if (!cuda_strategy_) {
multiple = 8;
if (nnz >= 1e7) {
if (nnz >= static_cast<int64_t>(1e7)) {
multiple = 64;
} else if (nnz >= 1e6) {
} else if (nnz >= static_cast<int64_t>(1e6)) {
multiple = 16;
}
}
Expand Down Expand Up @@ -484,13 +484,13 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,
const index_type nvidia_row_len_limit = 1024;
/* Use imbalance strategy when the matrix has more more than 1e6 on
* NVIDIA hardware */
const index_type nvidia_nnz_limit = 1e6;
const index_type nvidia_nnz_limit{static_cast<index_type>(1e6)};
/* Use imbalance strategy when the maximum number of nonzero per row is
* more than 768 on AMD hardware */
const index_type amd_row_len_limit = 768;
/* Use imbalance strategy when the matrix has more more than 1e8 on AMD
* hardware */
const index_type amd_nnz_limit = 1e8;
const index_type amd_nnz_limit{static_cast<index_type>(1e8)};

/**
* Creates an automatical strategy.
Expand Down
4 changes: 2 additions & 2 deletions include/ginkgo/core/stop/criterion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ public: \
_factory_name, _criterion, _parameters_name##_type> { \
friend class ::gko::EnablePolymorphicObject< \
_factory_name, ::gko::stop::CriterionFactory>; \
friend class ::gko::enable_parameters_type<_parameters_name##_type, \
_factory_name>; \
friend struct ::gko::enable_parameters_type<_parameters_name##_type, \
_factory_name>; \
explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec) \
: ::gko::stop::EnableDefaultCriterionFactory< \
_factory_name, _criterion, _parameters_name##_type>( \
Expand Down
9 changes: 4 additions & 5 deletions reference/test/matrix/ell_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class Ell : public ::testing::Test {
typename std::tuple_element<0, decltype(ValueIndexType())>::type;
using index_type =
typename std::tuple_element<1, decltype(ValueIndexType())>::type;
using T = value_type;
using Mtx = gko::matrix::Ell<value_type, index_type>;
using Csr = gko::matrix::Csr<value_type, index_type>;
using Vec = gko::matrix::Dense<value_type>;
Expand Down Expand Up @@ -94,10 +93,10 @@ class Ell : public ::testing::Test {
EXPECT_EQ(c[1], 1);
EXPECT_EQ(c[2], 2);
EXPECT_EQ(c[3], 1);
EXPECT_EQ(v[0], T{1.0});
EXPECT_EQ(v[1], T{3.0});
EXPECT_EQ(v[2], T{2.0});
EXPECT_EQ(v[3], T{5.0});
EXPECT_EQ(v[0], value_type{1.0});
EXPECT_EQ(v[1], value_type{3.0});
EXPECT_EQ(v[2], value_type{2.0});
EXPECT_EQ(v[3], value_type{5.0});
}

std::shared_ptr<const gko::Executor> exec;
Expand Down
9 changes: 4 additions & 5 deletions reference/test/matrix/hybrid_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class Hybrid : public ::testing::Test {
typename std::tuple_element<0, decltype(ValueIndexType())>::type;
using index_type =
typename std::tuple_element<1, decltype(ValueIndexType())>::type;
using T = value_type;
using Mtx = gko::matrix::Hybrid<value_type, index_type>;
using Vec = gko::matrix::Dense<value_type>;
using Csr = gko::matrix::Csr<value_type, index_type>;
Expand Down Expand Up @@ -119,10 +118,10 @@ class Hybrid : public ::testing::Test {
EXPECT_EQ(c[1], 1);
EXPECT_EQ(c[2], 2);
EXPECT_EQ(c[3], 1);
EXPECT_EQ(v[0], T{1.0});
EXPECT_EQ(v[1], T{3.0});
EXPECT_EQ(v[2], T{2.0});
EXPECT_EQ(v[3], T{5.0});
EXPECT_EQ(v[0], value_type{1.0});
EXPECT_EQ(v[1], value_type{3.0});
EXPECT_EQ(v[2], value_type{2.0});
EXPECT_EQ(v[3], value_type{5.0});
}

std::shared_ptr<const gko::ReferenceExecutor> exec;
Expand Down
4 changes: 2 additions & 2 deletions third_party/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ if(MSVC)
# Force using shared runtime library when MSVC builds shared libraries
ginkgo_load_git_package(gtest_external
"https://github.com/google/googletest.git"
"ee3aa831172090fd5442820f215cb04ab6062756"
"6a7ed316a5cdc07b6d26362c90770787513822d4"
# Work around the linking errors when compiling gtest with CUDA
"-Dgtest_disable_pthreads=ON" "-Dgtest_force_shared_crt=${BUILD_SHARED_LIBS}")
else()
ginkgo_load_git_package(gtest_external
"https://github.com/google/googletest.git"
"ee3aa831172090fd5442820f215cb04ab6062756"
"6a7ed316a5cdc07b6d26362c90770787513822d4"
# Work around the linking errors when compiling gtest with CUDA
"-Dgtest_disable_pthreads=ON"
"-DCMAKE_CXX_FLAGS=-fPIC")
Expand Down

0 comments on commit 541ae8b

Please sign in to comment.