Skip to content

Commit

Permalink
Merge pull request #324 from PDoakORNL/gpu_type_pollution_fix
Browse files Browse the repository at this point in the history
OSX build less broken
  • Loading branch information
PDoakORNL authored Feb 5, 2024
2 parents f0932a7 + 8333304 commit 8ae4b4b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 105 deletions.
7 changes: 5 additions & 2 deletions include/dca/linalg/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,12 @@ Matrix<ScalarType, device_name, ALLOC>::~Matrix() {

template <typename ScalarType, DeviceType device_name, class ALLOC>
void Matrix<ScalarType, device_name, ALLOC>::resize(std::pair<int, int> new_size) {
assert(new_size.first >= 0 && new_size.second >= 0);
if (new_size.first > capacity_.first || new_size.second > capacity_.second) {
if (new_size.first == 0 || new_size.second ==0) {
size_ = new_size;
return;
} else if (new_size.first > capacity_.first || new_size.second > capacity_.second) {
std::pair<int, int> new_capacity = capacityMultipleOfBlockSize(new_size);

ValueType* new_data = nullptr;
new_data = Allocator::allocate(nrElements(new_capacity));
// hip memorycpy2D routines don't tolerate leadingDimension = 0
Expand Down
3 changes: 2 additions & 1 deletion include/dca/linalg/util/gpu_type_mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ template <typename Real>
using GPUComplex = typename Real2MagmaComplex<Real>::type;
#endif


#ifdef DCA_HAVE_GPU
template <typename T>
__device__ __host__ HOSTPointerMap<T> castHostType(T var) {
if constexpr (std::is_same_v<HOSTPointerMap<T>, T>)
return var;
else if constexpr (std::is_pointer_v<T>)
return reinterpret_cast<HOSTPointerMap<T>>(var);
}
#endif

} // namespace util
} // namespace dca
Expand Down
2 changes: 2 additions & 0 deletions include/dca/platform/dca_gpu_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <cuComplex.h>
#endif

#ifdef DCA_HAVE_GPU
#include <magma_types.h>
#endif
#include "dca/util/type_fundamentals.hpp"

#if defined(DCA_HAVE_HIP)
Expand Down
71 changes: 0 additions & 71 deletions include/dca/util/ModernStringUtils.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/function/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_subdirectory(util)

dca_add_gtest(function_library_test
GTEST_MAIN
LIBS function)
LIBS function modern_string_utils)

if (function_library_test)
# We want to test self-assignment and self-move.
Expand Down
66 changes: 38 additions & 28 deletions test/unit/function/function_library_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,49 @@
#include "dca/util/type_list.hpp"
#include "dca/util/type_help.hpp"
#include "function_testing.hpp"
#include <ModernStringUtils.hpp>

namespace dca {
namespace testing {
// dca::testing::

/** basically this ignores whitespace for comparing output of the type ouput.
* this is necessary because libc++ inserts spaces between trailing template type brackets which is
* legal and was required by some older c++ stds.
*/
bool checkTypeLine(const std::string_view& expected, const std::string_view& test) {
auto expected_tokens = modernstrutil::split(expected, " \t");
auto test_tokens = modernstrutil::split(test, " \t");
if (expected_tokens.size() != test_tokens.size())
return false;
for (int i = 0; i < expected_tokens.size(); ++i)
if (expected_tokens[i] != test_tokens[i])
return false;
return true;
}

bool compare_to_file(const std::string& filename, const std::string& check) {
// Open the file.
std::ifstream known_result(filename);

auto test_lines = modernstrutil::split(check, "\n");
if (known_result.good()) {
std::string contents;

// Get the right size to reserve it.
known_result.seekg(0, std::ios::end);
contents.reserve(known_result.tellg());

known_result.seekg(0, std::ios::beg);

// Read contents into string directly.
contents.assign((std::istreambuf_iterator<char>(known_result)), std::istreambuf_iterator<char>());

return (contents == check);
std::string expected_line;
auto test_line = test_lines.begin();
while (std::getline(known_result, expected_line)) {
if (test_line == test_lines.end())
return false;
else if (!checkTypeLine(expected_line, *test_line))
return false;
++test_line;
return true;
}
}

else {
std::ofstream new_result(filename);
auto test_line = test_lines.begin();
new_result << check.c_str();
std::cout << "No baseline file exists, writing new one " << filename.c_str() << std::endl;
}

return false;
}

Expand All @@ -80,24 +93,24 @@ Domain16v dummy2;

TEST(Function, TestDomain4a) {
try {
std::cout << "Leaf indexing \n";
// std::cout << "Leaf indexing \n";
int index = 0;
for (int i0 = 0; i0 < 1; ++i0) {
for (int i1 = 0; i1 < 2; ++i1) {
for (int i2 = 0; i2 < 4; ++i2) {
for (int i3 = 0; i3 < 8; ++i3) {
std::cout << i0 << "," << i1 << "," << i2 << "," << i3 << "\n";
// std::cout << i0 << "," << i1 << "," << i2 << "," << i3 << "\n";
dca::testing::function_4a.operator()(i0, i1, i2, i3) = index++;
// dca::testing::function_4a.operator()(i3,i2,i1,i0) = index; bad ordering
}
}
}
}
std::cout << "Branch indexing \n";
// std::cout << "Branch indexing \n";
index = 0;
for (int i0 = 0; i0 < 2; ++i0) {
for (int i1 = 0; i1 < 32; ++i1) {
std::cout << i0 << "," << i1 << "\n";
// std::cout << i0 << "," << i1 << "\n";
dca::testing::function_4a.operator()(i0, i1) = index++;
}
}
Expand Down Expand Up @@ -145,7 +158,8 @@ TEST(Function, FingerPrint) {

std::cout << result.str();
EXPECT_TRUE(dca::testing::compare_to_file(DCA_SOURCE_DIR "/test/unit/function/fingerprint.txt",
result.str()));
result.str()))
<< result.str();
}

TEST(Function, PrintElements) {
Expand Down Expand Up @@ -480,9 +494,9 @@ TEST(FunctionTest, BranchIndexingAndAssignment) {
int size_domain2c = Domain2c::dmn_size();
EXPECT_EQ(size_domain2c, 32);
auto& branched_steps = branched_function.get_domain().get_branch_domain_steps();
std::cout << "branched_steps: " << vectorToString(branched_steps) << '\n';
// std::cout << "branched_steps: " << vectorToString(branched_steps) << '\n';
auto& branch_sizes = branched_function.get_domain().get_branch_domain_sizes();
std::cout << "branched_sizes: " << vectorToString(branch_sizes) << '\n';
// std::cout << "branched_sizes: " << vectorToString(branch_sizes) << '\n';
auto get_steps = [](const std::vector<unsigned long>& sbdm_sizes) {
std::vector<unsigned long> sbdm_steps(sbdm_sizes.size(), 1);
for (int i = 1; i < sbdm_steps.size(); ++i)
Expand All @@ -505,8 +519,8 @@ TEST(FunctionTest, BranchIndexingAndAssignment) {

EXPECT_EQ(branched_function.size(), 4096);
EXPECT_EQ(branched_function.getValues().size(), 4096);
std::cout << vectorToString(branched_function.getValues()) << '\n';
std::cout << vectorToString(branched_function_test.f.getValues()) << '\n';
// std::cout << vectorToString(branched_function.getValues()) << '\n';
// std::cout << vectorToString(branched_function_test.f.getValues()) << '\n';
}

TEST(FunctionTest, ArrayBasedIndexing) {
Expand All @@ -531,8 +545,6 @@ TEST(FunctionTest, ArrayBasedIndexing) {
f2c0c0c.linind_2_subind(
i2c + c2 * Domain2c::dmn_size() + c1 * Domain0c::dmn_size() * Domain2c::dmn_size(),
subind);
if (subind[2] > 0)
std::cout << "break";
subind_transpose[1] = subind[0];
subind_transpose[0] = subind[1];
subind_transpose[2] = subind[2];
Expand All @@ -558,8 +570,6 @@ TEST(FunctionTest, ArrayBasedIndexing) {
for (int c2 = 0; c2 < Domain0a::dmn_size(); c2++)
for (int i2c = 0; i2c < Domain2c::dmn_size(); i2c++) {
f2c0a0c.linind_2_subind(linind++, subind);
if (subind[2] > 0)
std::cout << "break";
subind_transpose[1] = subind[0];
subind_transpose[0] = subind[1];
subind_transpose[2] = subind[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ TYPED_TEST(DMatrixBuilderGpuTest, RemoveAndInstertVertex) {
Matrix<Scalar, CPU> G0;
Matrix<Scalar, GPU> G0_dev;
dca::linalg::util::GpuStream stream;

const std::vector<int> sizes{1, 3, 8};

// Should d_matrices_be_buildable for delta >= sizes? I don't think so but
// I don't know that we have any guarantee such won't occur the code related to that in ctint is hard to audit.

const std::vector<int> sizes{4, 5, 11};
const std::vector<int> deltas{1, 2, 3};
int s(0);
bool right_sector = true;
Expand Down

0 comments on commit 8ae4b4b

Please sign in to comment.