AllToAllVTests.cpp 6.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*************************************************************************
 * Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
 *
 * See LICENSE.txt for license information
 ************************************************************************/

 // Note: InPlace is not supported for All-To-Allv
 
#include "TestBed.hpp"

namespace RcclUnitTesting
{
  // Prepare sendcount/recvcounts, sdispls/rdispls arrays within options
  void PrepareCounts(int const totalRanks, int const chunkSize,
                     OptionalColArgs& options,
                     std::vector<size_t>& numInputElements,
                     std::vector<size_t>& numOutputElements)
  {
    numInputElements.clear();
    numOutputElements.clear();
    numInputElements.resize(totalRanks, 0);
    numOutputElements.resize(totalRanks, 0);

    // Decide how many elements each pair send/recv
    for (int sendRank = 0; sendRank < totalRanks; ++sendRank)
    for (int recvRank = 0; recvRank < totalRanks; ++recvRank)
    {
      // Get linear indices into sendcounts/recvcounts array
      int const sendIdx = sendRank * totalRanks + recvRank;
      int const recvIdx = recvRank * totalRanks + sendRank;

      // Each pair sends slightly different amounts of elements (based on chunkSize)
      int const numElements = (1 + sendRank + recvRank) * chunkSize;
      options.sendcounts[sendIdx]  = options.recvcounts[recvIdx] = numElements;
    }

    // Compute displacements
    for (int sendRank = 0; sendRank < totalRanks; ++sendRank)
    {
      int totalSend = 0;
      int totalRecv = 0;

      for (int recvRank = 0; recvRank < totalRanks; ++recvRank)
      {
        int const pairIdx = sendRank * totalRanks + recvRank;

        options.sdispls[pairIdx] = totalSend;
        options.rdispls[pairIdx] = totalRecv;

        totalSend += options.sendcounts[pairIdx];
        totalRecv += options.recvcounts[pairIdx];
      }

      numInputElements[sendRank] = totalSend;
      numOutputElements[sendRank] = totalRecv;
    }
  }

  TEST(AllToAllv, OutOfPlace)
  {
    TestBed testBed;

    // Configuration
    std::vector<ncclDataType_t> const& dataTypes       = {ncclInt32, ncclFloat64, ncclFloat16};
    bool                        const  inPlace         = false;
    bool                        const  useManagedMem   = false;
    bool                        const  useHipGraph     = false;

    OptionalColArgs options;

    bool isCorrect = true;
    for (int totalRanks : testBed.ev.GetNumGpusList())
    for (int isMultiProcess : testBed.ev.GetIsMultiProcessList())
    {
      int const numProcesses = isMultiProcess ? totalRanks : 1;
      testBed.InitComms(TestBed::GetDeviceIdsList(numProcesses, totalRanks));

      // Prepare AllToAllV options
      std::vector<size_t> numInputElements;
      std::vector<size_t> numOutputElements;
      PrepareCounts(totalRanks, 256, options, numInputElements, numOutputElements);

      for (int dataIdx = 0; dataIdx < dataTypes.size() && isCorrect; ++dataIdx)
      {
        if (testBed.ev.showNames)
        {
          std::string name = testBed.GetTestCaseName(totalRanks, isMultiProcess,
                                                     ncclCollAllToAllv, dataTypes[dataIdx],
                                                     ncclSum, -1, inPlace, useManagedMem, useHipGraph);
          INFO("%s\n", name.c_str());
        }

        for (int rank = 0; rank < totalRanks; ++rank)
        {
          testBed.SetCollectiveArgs(ncclCollAllToAllv,
                                    dataTypes[dataIdx],
                                    numInputElements[rank],
                                    numOutputElements[rank],
                                    options,
                                    -1,
                                    rank);
        }
        testBed.AllocateMem(inPlace, useManagedMem);
        testBed.PrepareData();
        testBed.ExecuteCollectives({}, useHipGraph);
        testBed.ValidateResults(isCorrect);
        testBed.DeallocateMem();
      }
      testBed.DestroyComms();
    }
    testBed.Finalize();
  }


  TEST(AllToAllv, OutOfPlaceGraph)
  {
    TestBed testBed;

    // Configuration
    std::vector<ncclDataType_t> const& dataTypes       = {ncclFloat32, ncclInt8};
    bool                        const  inPlace         = false;
    bool                        const  useManagedMem   = false;
    bool                        const  useHipGraph     = false;

    OptionalColArgs options;

    bool isCorrect = true;
    for (int totalRanks : testBed.ev.GetNumGpusList())
    for (int isMultiProcess : testBed.ev.GetIsMultiProcessList())
    {
      int const numProcesses = isMultiProcess ? totalRanks : 1;
      testBed.InitComms(TestBed::GetDeviceIdsList(numProcesses, totalRanks));

      // Prepare AllToAllV options
      std::vector<size_t> numInputElements;
      std::vector<size_t> numOutputElements;
      PrepareCounts(totalRanks, 256, options, numInputElements, numOutputElements);

      for (int dataIdx = 0; dataIdx < dataTypes.size() && isCorrect; ++dataIdx)
      {
        if (testBed.ev.showNames)
        {
          std::string name = testBed.GetTestCaseName(totalRanks, isMultiProcess,
                                                     ncclCollAllToAllv, dataTypes[dataIdx],
                                                     ncclSum, -1, inPlace, useManagedMem, useHipGraph);
          INFO("%s\n", name.c_str());
        }

        for (int rank = 0; rank < totalRanks; ++rank)
        {
          testBed.SetCollectiveArgs(ncclCollAllToAllv,
                                    dataTypes[dataIdx],
                                    numInputElements[rank],
                                    numOutputElements[rank],
                                    options,
                                    -1,
                                    rank);
        }
        testBed.AllocateMem(inPlace, useManagedMem);
        testBed.PrepareData();
        testBed.ExecuteCollectives({}, useHipGraph);
        testBed.ValidateResults(isCorrect);
        testBed.DeallocateMem();
      }
      testBed.DestroyComms();
    }
    testBed.Finalize();
  }
}