LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
distconv_scatter.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_SCATTER
28 #define LBANN_LAYERS_TRANSFORM_DISTCONV_SCATTER
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 Scatter
42 {
44 
45 public:
46  Scatter(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  template <typename Allocator>
67  void
68  setup(const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& input,
69  const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& indices,
70  const tensor::Tensor<DataType, tensor::LocaleMPI, Allocator>& output);
71 
72 protected:
73  Backend& m_backend;
74  std::unique_ptr<tensor::ScatterNVSHMEM<DataType>>
75  m_dist_scatter; // Forward prop
76  std::unique_ptr<tensor::GatherNVSHMEM<DataType>>
77  m_dist_gather; // Backwad prop
78 }; // class definition Scatter
79 } // namespace distconv
80 #endif // defined(LBANN_HAS_NVSHMEM) && defined(LBANN_HAS_DISTCONV)
81 #endif // LBANN_LAYERS_TRANSFORM_DISTCONV_SCATTER
::distconv::tensor::LocaleMPI LocaleMPI