diff options
author | Jerry Zhang <jerryzh@fb.com> | 2018-10-29 11:09:15 -0700 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2018-10-29 11:11:19 -0700 |
commit | dcbca53e58f1661216e716177cdb87590281cb34 (patch) | |
tree | 697ae30cbc0fcb1c8f30aa867a8b873bf42abfb1 /caffe2/mpi | |
parent | b1cf3ad1c2f62ccca241cfb6885b7716a348467f (diff) | |
download | pytorch-dcbca53e58f1661216e716177cdb87590281cb34.tar.gz pytorch-dcbca53e58f1661216e716177cdb87590281cb34.tar.bz2 pytorch-dcbca53e58f1661216e716177cdb87590281cb34.zip |
Renaming size() to numel() - 1/6
Summary: Codemod generated with clangr shard mode, 50 files per diff
Reviewed By: li-roy
Differential Revision: D10866373
fbshipit-source-id: 589194164d4fea93b74d83fa7fc4c59558c41f4a
Diffstat (limited to 'caffe2/mpi')
-rw-r--r-- | caffe2/mpi/mpi_gpu_test.cc | 28 | ||||
-rw-r--r-- | caffe2/mpi/mpi_ops.h | 10 | ||||
-rw-r--r-- | caffe2/mpi/mpi_test.cc | 28 |
3 files changed, 33 insertions, 33 deletions
diff --git a/caffe2/mpi/mpi_gpu_test.cc b/caffe2/mpi/mpi_gpu_test.cc index 0418186a43..0ce52cb675 100644 --- a/caffe2/mpi/mpi_gpu_test.cc +++ b/caffe2/mpi/mpi_gpu_test.cc @@ -66,8 +66,8 @@ TEST(MPITest, TestMPIBroadcast) { // Let's test the value. auto& X = ws.GetBlob("X")->Get<Tensor>(); Tensor X_cpu(X, CPU); - EXPECT_EQ(X.size(), 10); - for (int i = 0; i < X.size(); ++i) { + EXPECT_EQ(X.numel(), 10); + for (int i = 0; i < X.numel(); ++i) { EXPECT_EQ(X_cpu.data<float>()[i], root); } } @@ -132,10 +132,10 @@ TEST(MPITest, TestMPIReduce) { if (rank == root) { // Let's test the value. auto& X = ws.GetBlob("X_reduced")->Get<TensorCUDA>(); - EXPECT_EQ(X.size(), 10); + EXPECT_EQ(X.numel(), 10); int expected_result = size * (size - 1) / 2; Tensor X_cpu(X, CPU); - for (int i = 0; i < X.size(); ++i) { + for (int i = 0; i < X.numel(); ++i) { EXPECT_EQ(X_cpu.data<float>()[i], expected_result); } } @@ -192,16 +192,16 @@ TEST(MPITest, TestMPIAllgather) { // Let's test the value. auto& X = ws.GetBlob("X")->Get<TensorCUDA>(); Tensor X_cpu(X, CPU); - EXPECT_EQ(X.size(), 20); - for (int i = 0; i < X.size(); ++i) { + EXPECT_EQ(X.numel(), 20); + for (int i = 0; i < X.numel(); ++i) { EXPECT_EQ(X_cpu.data<float>()[i], rank); } auto& X_gathered = ws.GetBlob("X_gathered")->Get<TensorCUDA>(); - EXPECT_EQ(X_gathered.size(), 20 * size); + EXPECT_EQ(X_gathered.numel(), 20 * size); EXPECT_EQ(X_gathered.dim(0), 2 * size); EXPECT_EQ(X_gathered.dim(1), 10); Tensor X_gathered_cpu(X_gathered, CPU); - for (int i = 0; i < X_gathered.size(); ++i) { + for (int i = 0; i < X_gathered.numel(); ++i) { EXPECT_EQ(X_gathered_cpu.data<float>()[i], i / 20); } } @@ -254,16 +254,16 @@ TEST(MPITest, TestMPIAllreduce) { EXPECT_TRUE(net->Run()); // Let's test the value. auto& X = ws.GetBlob("X")->Get<TensorCUDA>(); - EXPECT_EQ(X.size(), 10); + EXPECT_EQ(X.numel(), 10); Tensor X_cpu(X, CPU); - for (int i = 0; i < X.size(); ++i) { + for (int i = 0; i < X.numel(); ++i) { EXPECT_EQ(X_cpu.data<float>()[i], rank); } auto& X_reduced = ws.GetBlob("X_reduced")->Get<TensorCUDA>(); - EXPECT_EQ(X_reduced.size(), 10); + EXPECT_EQ(X_reduced.numel(), 10); int expected_result = size * (size - 1) / 2; Tensor X_reduced_cpu(X_reduced, CPU); - for (int i = 0; i < X_reduced.size(); ++i) { + for (int i = 0; i < X_reduced.numel(); ++i) { EXPECT_EQ(X_reduced_cpu.data<float>()[i], expected_result); } } @@ -315,10 +315,10 @@ TEST(MPITest, TestInPlaceMPIAllreduce) { EXPECT_NE(nullptr, net.get()); EXPECT_TRUE(net->Run()); auto& X_reduced = ws.GetBlob("X")->Get<TensorCUDA>(); - EXPECT_EQ(X_reduced.size(), 10); + EXPECT_EQ(X_reduced.numel(), 10); int expected_result = size * (size - 1) / 2; Tensor X_reduced_cpu(X_reduced, CPU); - for (int i = 0; i < X_reduced.size(); ++i) { + for (int i = 0; i < X_reduced.numel(); ++i) { EXPECT_EQ(X_reduced_cpu.data<float>()[i], expected_result); } } diff --git a/caffe2/mpi/mpi_ops.h b/caffe2/mpi/mpi_ops.h index 6f759900f3..0580a7764c 100644 --- a/caffe2/mpi/mpi_ops.h +++ b/caffe2/mpi/mpi_ops.h @@ -41,7 +41,7 @@ class MPIBroadcastOp final : public Operator<Context> { auto* output = Output(0); // Make sure that output is already allocated. CAFFE_ENFORCE( - output->size() > 0, + output->numel() > 0, "Broadcast op uses in-place operation so the output " "should be already allocated."); MPI_CHECK(MPI_Bcast( @@ -75,7 +75,7 @@ class MPIReduceOp final : public Operator<Context> { MPI_CHECK(MPI_Reduce( const_cast<T*>(input.template data<T>()), output->template mutable_data<T>(), - input.size(), + input.numel(), MPIDataTypeWrapper<T>::type(), MPI_SUM, root_, @@ -103,10 +103,10 @@ class MPIAllgatherOp final : public Operator<Context> { output->Resize(output_dims); MPI_CHECK(MPI_Allgather( const_cast<T*>(input.template data<T>()), - input.size(), + input.numel(), MPIDataTypeWrapper<T>::type(), output->template mutable_data<T>(), - input.size(), + input.numel(), MPIDataTypeWrapper<T>::type(), comm)); return true; @@ -136,7 +136,7 @@ class MPIAllreduceOp final : public Operator<Context> { MPI_CHECK(MPI_Allreduce( source, output->template mutable_data<T>(), - input.size(), + input.numel(), MPIDataTypeWrapper<T>::type(), MPI_SUM, comm)); diff --git a/caffe2/mpi/mpi_test.cc b/caffe2/mpi/mpi_test.cc index d5e081a57f..4e70e23aea 100644 --- a/caffe2/mpi/mpi_test.cc +++ b/caffe2/mpi/mpi_test.cc @@ -62,8 +62,8 @@ TEST(MPITest, TestMPIBroadcast) { EXPECT_TRUE(net->Run()); // Let's test the value. auto& X = ws.GetBlob("X")->Get<TensorCPU>(); - EXPECT_EQ(X.size(), 10); - for (int i = 0; i < X.size(); ++i) { + EXPECT_EQ(X.numel(), 10); + for (int i = 0; i < X.numel(); ++i) { EXPECT_EQ(X.data<float>()[i], root); } } @@ -125,9 +125,9 @@ TEST(MPITest, TestMPIReduce) { if (rank == root) { // Let's test the value. auto& X = ws.GetBlob("X_reduced")->Get<TensorCPU>(); - EXPECT_EQ(X.size(), 10); + EXPECT_EQ(X.numel(), 10); int expected_result = size * (size - 1) / 2; - for (int i = 0; i < X.size(); ++i) { + for (int i = 0; i < X.numel(); ++i) { EXPECT_EQ(X.data<float>()[i], expected_result); } } @@ -180,15 +180,15 @@ TEST(MPITest, TestMPIAllgather) { EXPECT_TRUE(net->Run()); // Let's test the value. auto& X = ws.GetBlob("X")->Get<TensorCPU>(); - EXPECT_EQ(X.size(), 20); - for (int i = 0; i < X.size(); ++i) { + EXPECT_EQ(X.numel(), 20); + for (int i = 0; i < X.numel(); ++i) { EXPECT_EQ(X.data<float>()[i], rank); } auto& X_gathered = ws.GetBlob("X_gathered")->Get<TensorCPU>(); - EXPECT_EQ(X_gathered.size(), 20 * size); + EXPECT_EQ(X_gathered.numel(), 20 * size); EXPECT_EQ(X_gathered.dim(0), 2 * size); EXPECT_EQ(X_gathered.dim(1), 10); - for (int i = 0; i < X_gathered.size(); ++i) { + for (int i = 0; i < X_gathered.numel(); ++i) { EXPECT_EQ(X_gathered.data<float>()[i], i / 20); } } @@ -238,14 +238,14 @@ TEST(MPITest, TestMPIAllreduce) { EXPECT_TRUE(net->Run()); // Let's test the value. auto& X = ws.GetBlob("X")->Get<TensorCPU>(); - EXPECT_EQ(X.size(), 10); - for (int i = 0; i < X.size(); ++i) { + EXPECT_EQ(X.numel(), 10); + for (int i = 0; i < X.numel(); ++i) { EXPECT_EQ(X.data<float>()[i], rank); } auto& X_reduced = ws.GetBlob("X_reduced")->Get<TensorCPU>(); - EXPECT_EQ(X_reduced.size(), 10); + EXPECT_EQ(X_reduced.numel(), 10); int expected_result = size * (size - 1) / 2; - for (int i = 0; i < X_reduced.size(); ++i) { + for (int i = 0; i < X_reduced.numel(); ++i) { EXPECT_EQ(X_reduced.data<float>()[i], expected_result); } } @@ -294,9 +294,9 @@ TEST(MPITest, TestInPlaceMPIAllreduce) { EXPECT_NE(nullptr, net.get()); EXPECT_TRUE(net->Run()); auto& X_reduced = ws.GetBlob("X")->Get<TensorCPU>(); - EXPECT_EQ(X_reduced.size(), 10); + EXPECT_EQ(X_reduced.numel(), 10); int expected_result = size * (size - 1) / 2; - for (int i = 0; i < X_reduced.size(); ++i) { + for (int i = 0; i < X_reduced.numel(); ++i) { EXPECT_EQ(X_reduced.data<float>()[i], expected_result); } } |