提交 00572aa4 编写于 作者: L liaogang

Add memory alignment test

上级 ff98e3c1
...@@ -13,9 +13,13 @@ See the License for the specific language governing permissions and ...@@ -13,9 +13,13 @@ See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "paddle/memory/memory.h" #include "paddle/memory/memory.h"
#include "gtest/gtest.h"
#include "paddle/platform/place.h" #include "paddle/platform/place.h"
#include "gtest/gtest.h" template <typename T>
inline bool is_aligned(T *p, size_t n = alignof(T)) {
return 0 == (reinterpret_cast<uintptr_t>(p) % n);
}
TEST(BuddyAllocator, CPUAllocation) { TEST(BuddyAllocator, CPUAllocation) {
void *p = nullptr; void *p = nullptr;
...@@ -36,11 +40,13 @@ TEST(BuddyAllocator, CPUMultAlloc) { ...@@ -36,11 +40,13 @@ TEST(BuddyAllocator, CPUMultAlloc) {
std::vector<void *> ps; std::vector<void *> ps;
ps.reserve(8); ps.reserve(8);
for (auto size : {256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304}) { for (auto size :
{128, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304}) {
ps.emplace_back(paddle::memory::Alloc(cpu, size)); ps.emplace_back(paddle::memory::Alloc(cpu, size));
} }
for (auto p : ps) { for (auto p : ps) {
EXPECT_EQ(is_aligned(p, 32), true);
paddle::memory::Free(cpu, p); paddle::memory::Free(cpu, p);
} }
} }
...@@ -60,4 +66,21 @@ TEST(BuddyAllocator, GPUAllocation) { ...@@ -60,4 +66,21 @@ TEST(BuddyAllocator, GPUAllocation) {
paddle::memory::Free(gpu, p); paddle::memory::Free(gpu, p);
} }
TEST(BuddyAllocator, GPUMultAlloc) {
paddle::platform::GPUPlace gpu;
std::vector<void *> ps;
ps.reserve(8);
for (auto size :
{128, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304}) {
ps.emplace_back(paddle::memory::Alloc(gpu, size));
}
for (auto p : ps) {
EXPECT_EQ(is_aligned(p, 32), true);
paddle::memory::Free(gpu, p);
}
}
#endif // PADDLE_ONLY_CPU #endif // PADDLE_ONLY_CPU
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册