mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/10946 ``` codemod -d . --extensions cc,cpp,cu,cuh,h caffe2/proto/caffe2.pb.h caffe2/proto/caffe2_pb.h ``` Reviewed By: houseroad Differential Revision: D9539945 fbshipit-source-id: 497d04720e8e7e61c05ffe1b23733d0cb774de7e
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#include <random>
|
|
|
|
#include <gtest/gtest.h>
|
|
#include "caffe2/core/context.h"
|
|
#include "caffe2/proto/caffe2_pb.h"
|
|
|
|
namespace caffe2 {
|
|
|
|
TEST(CPUContextTest, ATenCoreTest) {
|
|
int i = at::CoreTest();
|
|
EXPECT_EQ(i + 1, at::CoreTest());
|
|
}
|
|
|
|
TEST(CPUContextTest, TestAllocAlignment) {
|
|
for (int i = 1; i < 10; ++i) {
|
|
auto data = CPUContext::New(i);
|
|
EXPECT_EQ((reinterpret_cast<size_t>(data.first) % gCaffe2Alignment), 0);
|
|
data.second(data.first);
|
|
}
|
|
}
|
|
|
|
TEST(CPUContextTest, TestAllocDealloc) {
|
|
auto data_and_deleter = CPUContext::New(10 * sizeof(float));
|
|
float* data = static_cast<float*>(data_and_deleter.first);
|
|
EXPECT_NE(data, nullptr);
|
|
auto dst_data_and_deleter = CPUContext::New(10 * sizeof(float));
|
|
float* dst_data = static_cast<float*>(dst_data_and_deleter.first);
|
|
EXPECT_NE(dst_data, nullptr);
|
|
for (int i = 0; i < 10; ++i) {
|
|
data[i] = i;
|
|
}
|
|
DeviceOption option;
|
|
CPUContext context(option);
|
|
context.CopyToCPU<float>(10, data, dst_data);
|
|
for (int i = 0; i < 10; ++i) {
|
|
EXPECT_FLOAT_EQ(dst_data[i], i);
|
|
}
|
|
data_and_deleter.second(data);
|
|
dst_data_and_deleter.second(dst_data);
|
|
}
|
|
|
|
} // namespace caffe2
|