mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/12232 Original commit changeset: fca91fea58b7 This adds proper modifications to the DeviceType <->DeviceOption conversion code added in D10033396 Reviewed By: jerryzh168 Differential Revision: D10132473 fbshipit-source-id: 801ef777e2950982cb47b48051b1471a0a91e64b
33 lines
921 B
C++
33 lines
921 B
C++
#include "caffe2/utils/proto_utils.h"
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace caffe2 {
|
|
|
|
TEST(ProtoUtilsTest, IsSameDevice) {
|
|
DeviceOption a;
|
|
DeviceOption b;
|
|
EXPECT_TRUE(IsSameDevice(a, b));
|
|
a.set_node_name("my_node");
|
|
EXPECT_FALSE(IsSameDevice(a, b));
|
|
b.set_node_name("my_node");
|
|
EXPECT_TRUE(IsSameDevice(a, b));
|
|
b.set_cuda_gpu_id(2);
|
|
EXPECT_FALSE(IsSameDevice(a, b));
|
|
a.set_cuda_gpu_id(2);
|
|
EXPECT_TRUE(IsSameDevice(a, b));
|
|
a.set_device_type(DeviceTypeProto::PROTO_CUDA);
|
|
b.set_device_type(DeviceTypeProto::PROTO_CPU);
|
|
EXPECT_FALSE(IsSameDevice(a, b));
|
|
}
|
|
|
|
TEST(ProtoUtilsTest, SimpleReadWrite) {
|
|
string content("The quick brown fox jumps over the lazy dog.");
|
|
string name = std::tmpnam(nullptr);
|
|
EXPECT_TRUE(WriteStringToFile(content, name.c_str()));
|
|
string read_back;
|
|
EXPECT_TRUE(ReadStringFromFile(name.c_str(), &read_back));
|
|
EXPECT_EQ(content, read_back);
|
|
}
|
|
|
|
} // namespace caffe2
|