From f45b5e37d3e10ff527ec6a14c5abedd40057bca8 Mon Sep 17 00:00:00 2001 From: Shuji SUZUKI Date: Mon, 7 May 2018 16:42:50 +0900 Subject: [PATCH] Replace get_device (#231) * use get_device_from_id * replace all get_device --- docs/source/tutorial/step1_communicators_optimizers.rst | 4 ++-- examples/imagenet/train_imagenet.py | 2 +- examples/mnist/train_mnist.py | 2 +- examples/mnist/train_mnist_checkpoint.py | 2 +- examples/mnist/train_mnist_dual_parallel.py | 2 +- examples/mnist/train_mnist_model_parallel.py | 2 +- examples/seq2seq/seq2seq.py | 2 +- examples/seq2seq/seq2seq_mp1.py | 2 +- tests/chainermn_tests/communicator_tests/test_communicator.py | 2 +- tests/chainermn_tests/datasets_tests/test_mnist.py | 2 +- .../extensions_tests/test_allreduce_persistent.py | 2 +- .../functions_tests/test_collective_communication.py | 2 +- .../functions_tests/test_point_to_point_communication.py | 2 +- .../chainermn_tests/links_tests/test_multi_node_chain_list.py | 2 +- tests/chainermn_tests/links_tests/test_n_step_rnn.py | 2 +- .../optimizer_tests/test_double_buffering_optimizer.py | 4 ++-- .../optimizer_tests/test_multi_node_optimizer.py | 4 ++-- 17 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/source/tutorial/step1_communicators_optimizers.rst b/docs/source/tutorial/step1_communicators_optimizers.rst index 430a61df..4365fd2e 100644 --- a/docs/source/tutorial/step1_communicators_optimizers.rst +++ b/docs/source/tutorial/step1_communicators_optimizers.rst @@ -25,12 +25,12 @@ Therefore, it is often convenient to use the ``intra_rank``-th GPU. The following line of code is found in the original MNIST example:: - chainer.cuda.get_device(args.gpu).use() + chainer.cuda.get_device_from_id(args.gpu).use() which we modify as follows:: device = comm.intra_rank - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() Creating a Multi-Node Optimizer diff --git a/examples/imagenet/train_imagenet.py b/examples/imagenet/train_imagenet.py index 9dea9e11..2042f168 100644 --- a/examples/imagenet/train_imagenet.py +++ b/examples/imagenet/train_imagenet.py @@ -149,7 +149,7 @@ def main(): print('Load model from', args.initmodel) chainer.serializers.load_npz(args.initmodel, model) - chainer.cuda.get_device(device).use() # Make the GPU current + chainer.cuda.get_device_from_id(device).use() # Make the GPU current model.to_gpu() # Split and distribute the dataset. Only worker 0 loads the whole dataset. diff --git a/examples/mnist/train_mnist.py b/examples/mnist/train_mnist.py index e48bf0e0..71aa3d30 100644 --- a/examples/mnist/train_mnist.py +++ b/examples/mnist/train_mnist.py @@ -74,7 +74,7 @@ def main(): model = L.Classifier(MLP(args.unit, 10)) if device >= 0: - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() model.to_gpu() # Create a multi node optimizer from a standard Chainer optimizer. diff --git a/examples/mnist/train_mnist_checkpoint.py b/examples/mnist/train_mnist_checkpoint.py index 6f0cb50a..d2372760 100644 --- a/examples/mnist/train_mnist_checkpoint.py +++ b/examples/mnist/train_mnist_checkpoint.py @@ -77,7 +77,7 @@ def main(): model = L.Classifier(MLP(args.unit, 10)) if device >= 0: - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() model.to_gpu() # Create a multi node optimizer from a standard Chainer optimizer. diff --git a/examples/mnist/train_mnist_dual_parallel.py b/examples/mnist/train_mnist_dual_parallel.py index f94aa279..c0d34bfa 100644 --- a/examples/mnist/train_mnist_dual_parallel.py +++ b/examples/mnist/train_mnist_dual_parallel.py @@ -110,7 +110,7 @@ def main(): model = MLP1(model_comm, args.unit, 10) if device >= 0: - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() model.to_gpu() optimizer = chainermn.create_multi_node_optimizer( diff --git a/examples/mnist/train_mnist_model_parallel.py b/examples/mnist/train_mnist_model_parallel.py index 60d31ac2..72e3b4df 100644 --- a/examples/mnist/train_mnist_model_parallel.py +++ b/examples/mnist/train_mnist_model_parallel.py @@ -103,7 +103,7 @@ def main(): model = MLP1(comm, args.unit, 10) if device >= 0: - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() model.to_gpu() optimizer = chainer.optimizers.Adam() diff --git a/examples/seq2seq/seq2seq.py b/examples/seq2seq/seq2seq.py index fdb0da7e..78661f11 100644 --- a/examples/seq2seq/seq2seq.py +++ b/examples/seq2seq/seq2seq.py @@ -427,7 +427,7 @@ def main(): model = Seq2seq(3, len(source_ids), len(target_ids), args.unit) if dev >= 0: - chainer.cuda.get_device(dev).use() + chainer.cuda.get_device_from_id(dev).use() model.to_gpu(dev) # determine the stop trigger diff --git a/examples/seq2seq/seq2seq_mp1.py b/examples/seq2seq/seq2seq_mp1.py index 74e1c62e..e27c4646 100644 --- a/examples/seq2seq/seq2seq_mp1.py +++ b/examples/seq2seq/seq2seq_mp1.py @@ -455,7 +455,7 @@ def main(): comm, n_lstm_layers, len(source_ids), len(target_ids), args.unit) if dev >= 0: - chainer.cuda.get_device(dev).use() + chainer.cuda.get_device_from_id(dev).use() model.to_gpu(dev) # determine the stop trigger diff --git a/tests/chainermn_tests/communicator_tests/test_communicator.py b/tests/chainermn_tests/communicator_tests/test_communicator.py index 23ac5147..f91503a3 100644 --- a/tests/chainermn_tests/communicator_tests/test_communicator.py +++ b/tests/chainermn_tests/communicator_tests/test_communicator.py @@ -117,7 +117,7 @@ def create_communicator(param, use_gpu): communicator = param.communicator_class(mpi_comm) if use_gpu: - chainer.cuda.get_device(communicator.intra_rank).use() + chainer.cuda.get_device_from_id(communicator.intra_rank).use() return communicator diff --git a/tests/chainermn_tests/datasets_tests/test_mnist.py b/tests/chainermn_tests/datasets_tests/test_mnist.py index 703031a1..7ea80ef9 100644 --- a/tests/chainermn_tests/datasets_tests/test_mnist.py +++ b/tests/chainermn_tests/datasets_tests/test_mnist.py @@ -37,7 +37,7 @@ def check_mnist(gpu, display_log=True): comm = chainermn.create_communicator('naive') if gpu: device = comm.intra_rank - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() else: device = -1 diff --git a/tests/chainermn_tests/extensions_tests/test_allreduce_persistent.py b/tests/chainermn_tests/extensions_tests/test_allreduce_persistent.py index ea0e1690..c1899f22 100644 --- a/tests/chainermn_tests/extensions_tests/test_allreduce_persistent.py +++ b/tests/chainermn_tests/extensions_tests/test_allreduce_persistent.py @@ -44,7 +44,7 @@ def test_allreduce_persistent_cpu(self): def test_allreduce_persistent_gpu(self): comm = chainermn.create_communicator('hierarchical') device = comm.intra_rank - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() model = ExampleModel() model.to_gpu() diff --git a/tests/chainermn_tests/functions_tests/test_collective_communication.py b/tests/chainermn_tests/functions_tests/test_collective_communication.py index 0c82891a..5fa04e46 100644 --- a/tests/chainermn_tests/functions_tests/test_collective_communication.py +++ b/tests/chainermn_tests/functions_tests/test_collective_communication.py @@ -17,7 +17,7 @@ def setup(self, gpu): if gpu: self.communicator = chainermn.create_communicator('hierarchical') self.device = self.communicator.intra_rank - chainer.cuda.get_device(self.device).use() + chainer.cuda.get_device_from_id(self.device).use() else: self.communicator = chainermn.create_communicator('naive') self.device = -1 diff --git a/tests/chainermn_tests/functions_tests/test_point_to_point_communication.py b/tests/chainermn_tests/functions_tests/test_point_to_point_communication.py index e4a5b9e3..10abd9c4 100644 --- a/tests/chainermn_tests/functions_tests/test_point_to_point_communication.py +++ b/tests/chainermn_tests/functions_tests/test_point_to_point_communication.py @@ -19,7 +19,7 @@ def setup(self, gpu): if self.gpu: self.communicator = chainermn.create_communicator('hierarchical') device = self.communicator.intra_rank - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() else: self.communicator = chainermn.create_communicator('naive') device = -1 diff --git a/tests/chainermn_tests/links_tests/test_multi_node_chain_list.py b/tests/chainermn_tests/links_tests/test_multi_node_chain_list.py index de7065d5..db28042e 100644 --- a/tests/chainermn_tests/links_tests/test_multi_node_chain_list.py +++ b/tests/chainermn_tests/links_tests/test_multi_node_chain_list.py @@ -205,7 +205,7 @@ def __init__(self, comm, size, rank_parent): def create_communicator(gpu): if gpu: communicator = chainermn.create_communicator('hierarchical') - chainer.cuda.get_device(communicator.intra_rank).use() + chainer.cuda.get_device_from_id(communicator.intra_rank).use() else: communicator = chainermn.create_communicator('naive') diff --git a/tests/chainermn_tests/links_tests/test_n_step_rnn.py b/tests/chainermn_tests/links_tests/test_n_step_rnn.py index 14d8f9bf..95b7a28e 100644 --- a/tests/chainermn_tests/links_tests/test_n_step_rnn.py +++ b/tests/chainermn_tests/links_tests/test_n_step_rnn.py @@ -43,7 +43,7 @@ class TestNStepRNN(unittest.TestCase): def setup(self, gpu): if gpu: self.communicator = chainermn.create_communicator('hierarchical') - chainer.cuda.get_device(self.communicator.intra_rank).use() + chainer.cuda.get_device_from_id(self.communicator.intra_rank).use() else: self.communicator = chainermn.create_communicator('naive') diff --git a/tests/chainermn_tests/optimizer_tests/test_double_buffering_optimizer.py b/tests/chainermn_tests/optimizer_tests/test_double_buffering_optimizer.py index a3b42818..61b75563 100644 --- a/tests/chainermn_tests/optimizer_tests/test_double_buffering_optimizer.py +++ b/tests/chainermn_tests/optimizer_tests/test_double_buffering_optimizer.py @@ -26,7 +26,7 @@ def setup_gpu(self, device=None): pytest.skip('This test requires NCCL version >= 2.0') self.comm = chainermn.create_communicator('pure_nccl') device = self.comm.intra_rank - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() self.target = ExampleModel() self.target.to_gpu() self.target.a.W.data[:] = self.comm.rank @@ -103,7 +103,7 @@ def setup_gpu(self, device=None): pytest.skip('This test requires NCCL version >= 2.0') self.comm = chainermn.create_communicator('pure_nccl') device = self.comm.intra_rank - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() self.target = DynamicExampleModel() self.target.to_gpu() self.target.a.W.data[:] = self.comm.rank diff --git a/tests/chainermn_tests/optimizer_tests/test_multi_node_optimizer.py b/tests/chainermn_tests/optimizer_tests/test_multi_node_optimizer.py index fca64fa9..def21a27 100644 --- a/tests/chainermn_tests/optimizer_tests/test_multi_node_optimizer.py +++ b/tests/chainermn_tests/optimizer_tests/test_multi_node_optimizer.py @@ -34,7 +34,7 @@ def setup_cpu(self): def setup_gpu(self, device=None): self.comm = chainermn.create_communicator('hierarchical') device = self.comm.intra_rank - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() self.target = ExampleModel() self.target.to_gpu() self.target.a.W.data[:] = self.comm.rank @@ -128,7 +128,7 @@ def setup_cpu(self): def setup_gpu(self, device=None): self.comm = chainermn.create_communicator('hierarchical') device = self.comm.intra_rank - chainer.cuda.get_device(device).use() + chainer.cuda.get_device_from_id(device).use() self.target = DynamicExampleModel() self.target.to_gpu() self.target.a.W.data[:] = self.comm.rank