LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
distconv_gather.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2019, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 
27 #ifndef LBANN_LAYERS_TRANSFORM_DISTCONV_GATHER
28 #define LBANN_LAYERS_TRANSFORM_DISTCONV_GATHER
29 
30 #include "lbann/utils/distconv.hpp"
31 
32 #if defined(LBANN_HAS_NVSHMEM) && defined(LBANN_HAS_DISTCONV)
33 
34 #include "distconv/base.hpp"
35 #include "distconv/tensor/tensor.hpp"
36 #include "distconv/tensor/tensor_mpi.hpp"
38 
39 namespace distconv {
40 template <typename Backend, typename DataType>
41 class Gather
42 {
44 
45 public:
46  Gather(Backend& backend) : m_backend(backend)
47  {
48  m_dist_scatter = std::make_unique<tensor::ScatterNVSHMEM<DataType>>(
49  m_backend.get_stream());
50  m_dist_gather = std::make_unique<tensor::GatherNVSHMEM<DataType>>(
51  m_backend.get_stream());
52  };
53 
54  template <typename Allocator>
55  int forward(
56  const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& input,
57  const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& indices,
58  tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& output);
59 
60  template <typename Allocator>
61  int backward(
62  const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& output_grad,
63  const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& indices,
64  tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& values_grad,
65  tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& indices_grad);
66 
67  template <typename Allocator>
68  void
69  setup(const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& input,
70  const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& indices,
71  const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& output);
72 
73 protected:
74  Backend& m_backend;
75  std::unique_ptr<tensor::GatherNVSHMEM<DataType>>
76  m_dist_gather; // Forward prop
77  std::unique_ptr<tensor::ScatterNVSHMEM<DataType>>
78  m_dist_scatter; // Backward prop
79 }; // class definition Gather
80 } // namespace distconv
81 
82 #endif // defined(LBANN_HAS_DISTCONV) && defined(LBANN_HAS_NVSHMEM)
83 #endif // LBANN_LAYERS_TRANSFORM_DISTCONV_GATHER
::distconv::tensor::LocaleMPI LocaleMPI