Skip to content

Commit

Permalink
pass all the test cases on CPP side
Browse files Browse the repository at this point in the history
  • Loading branch information
XJDKC committed Apr 8, 2020
1 parent 917c455 commit 9e77f54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion test/singa/test_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ using singa::Platform;
TEST(Platform, CreateMultDevice) {
int n = Platform::GetNumGPUs();
auto devs = Platform::CreateCudaGPUs(n);
for (int i = 0; i < devs.size(); i++) {
for (size_t i = 0; i < devs.size(); i++) {
auto b = devs[i]->NewBlock(512 + 512 * (2 - i));
// for lazy allocation
b->mutable_data();
EXPECT_EQ(512 + 512 * (2 - i), devs[i]->GetAllocatedMem());
devs[i]->FreeBlock(b);
}
Expand All @@ -54,6 +56,8 @@ TEST(Platform, CreateDevice) {
size_t size[] = {128, 256, 3, 24};
{
auto ptr = dev->NewBlock(size[0]);
// for lazy allocation
ptr->mutable_data();
auto allocated = dev->GetAllocatedMem();
EXPECT_LE(size[0], allocated);
dev->FreeBlock(ptr);
Expand All @@ -63,9 +67,13 @@ TEST(Platform, CreateDevice) {
auto ptr0 = dev->NewBlock(size[0]);
auto ptr1 = dev->NewBlock(size[1]);
auto ptr2 = dev->NewBlock(size[2]);
ptr0->mutable_data();
ptr1->mutable_data();
ptr2->mutable_data();
auto allocated = dev->GetAllocatedMem();
EXPECT_LE(size[0] + size[1] + size[2], allocated);
auto ptr3 = dev->NewBlock(size[3]);
ptr3->mutable_data();
allocated = dev->GetAllocatedMem();
EXPECT_LE(size[0] + size[1] + size[2] + size[3], allocated);
dev->FreeBlock(ptr0);
Expand Down
2 changes: 1 addition & 1 deletion test/singa/test_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ TEST(Snapshot, ReadIntTest) {
singa::Snapshot int_snapshot_write(prefix + ".int",
singa::Snapshot::kWrite);
singa::Tensor int_param(singa::Shape{4});
int_param.AsType(singa::kInt);
int_param.CopyDataFromHostPtr(int_data, 4);
int_param.AsType(singa::kInt);
int_snapshot_write.Write("IntParam", int_param);
}

Expand Down

0 comments on commit 9e77f54

Please sign in to comment.