-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add placeholder for memory utils unit tests.
- Loading branch information
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
add_subdirectory(matrix) | ||
add_subdirectory(vector) | ||
add_subdirectory(utilities) | ||
add_subdirectory(memory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#[[ | ||
@brief Build ReSolve memory utilities unit tests | ||
@author Slaven Peles <[email protected]> | ||
]] | ||
|
||
# Build memory utilities tests | ||
add_executable(runMemoryUtilsTests.exe runMemoryUtilsTests.cpp) | ||
target_link_libraries(runMemoryUtilsTests.exe PRIVATE ReSolve resolve_backend_hip) | ||
message(STATUS "Resolve libraries: ${resolve_backend_hip}") | ||
|
||
|
||
# Install tests | ||
set(installable_tests runMemoryUtilsTests.exe) | ||
install(TARGETS ${installable_tests} | ||
RUNTIME DESTINATION bin/resolve/tests/unit) | ||
|
||
# Add tests to run | ||
add_test(NAME memory_test COMMAND $<TARGET_FILE:runMemoryUtilsTests.exe>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
#include <sstream> | ||
#include <iterator> | ||
#include <algorithm> | ||
#include <resolve/MemoryUtils.hpp> | ||
#include <tests/unit/TestBase.hpp> | ||
|
||
namespace ReSolve { namespace tests { | ||
|
||
/** | ||
* @class Unit tests for memory handler class | ||
*/ | ||
class MemoryUtilsTests : TestBase | ||
{ | ||
public: | ||
MemoryUtilsTests(std::string memspace) : memspace_(memspace) | ||
{} | ||
virtual ~MemoryUtilsTests() | ||
{} | ||
|
||
TestOutcome allocateAndDelete() | ||
{ | ||
TestStatus status; | ||
status = true; | ||
|
||
MemoryHandler mh; | ||
|
||
index_type n = 1000; | ||
size_t m = 8000; | ||
index_type* i = nullptr; | ||
real_type* r = nullptr; | ||
|
||
mh.allocateArrayOnDevice(&i, n); | ||
mh.allocateBufferOnDevice((void**) &r, m); | ||
|
||
status *= (i != nullptr); | ||
status *= (r != nullptr); | ||
|
||
mh.deleteOnDevice(i); | ||
mh.deleteOnDevice(r); | ||
|
||
return status.report(__func__); | ||
} | ||
|
||
|
||
private: | ||
std::string memspace_{"cpu"}; | ||
|
||
// bool verifyAnswer(vector::Vector& x, real_type answer, std::string memspace) | ||
// { | ||
// bool status = true; | ||
// if (memspace != "cpu") { | ||
// x.copyData(memspace, "cpu"); | ||
// } | ||
|
||
// for (index_type i = 0; i < x.getSize(); ++i) { | ||
// // std::cout << x.getData("cpu")[i] << "\n"; | ||
// if (!isEqual(x.getData("cpu")[i], answer)) { | ||
// status = false; | ||
// std::cout << "Solution vector element x[" << i << "] = " << x.getData("cpu")[i] | ||
// << ", expected: " << answer << "\n"; | ||
// break; | ||
// } | ||
// } | ||
// return status; | ||
// } | ||
|
||
}; // class MemoryUtilsTests | ||
|
||
}} // namespace ReSolve::tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
#include "MemoryUtilsTests.hpp" | ||
|
||
int main(int, char**) | ||
{ | ||
ReSolve::tests::TestingResults result; | ||
|
||
#ifdef RESOLVE_USE_HIP | ||
{ | ||
std::cout << "Running memory tests with HIP backend:\n"; | ||
ReSolve::tests::MemoryUtilsTests test("hip"); | ||
|
||
result += test.allocateAndDelete(); | ||
|
||
std::cout << "\n"; | ||
} | ||
#endif | ||
|
||
#ifdef RESOLVE_USE_CUDA | ||
{ | ||
std::cout << "Running memory tests with CUDA backend:\n"; | ||
ReSolve::tests::MemoryUtilsTests test("hip"); | ||
|
||
result += test.allocateAndDelete(); | ||
|
||
std::cout << "\n"; | ||
} | ||
#endif | ||
|
||
return result.summary(); | ||
} |