From 9e77f54340ccd66033cc04636e4b2e8dfe59e77e Mon Sep 17 00:00:00 2001 From: xjdkc Date: Wed, 8 Apr 2020 16:25:59 +0000 Subject: [PATCH] pass all the test cases on CPP side --- test/singa/test_platform.cc | 10 +++++++++- test/singa/test_snapshot.cc | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/singa/test_platform.cc b/test/singa/test_platform.cc index c38ef37e52..fce5f347ab 100644 --- a/test/singa/test_platform.cc +++ b/test/singa/test_platform.cc @@ -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); } @@ -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); @@ -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); diff --git a/test/singa/test_snapshot.cc b/test/singa/test_snapshot.cc index 43c879c7cc..ab1a69ff31 100644 --- a/test/singa/test_snapshot.cc +++ b/test/singa/test_snapshot.cc @@ -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); }