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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "../../shared/accuracy_test.h"
#include "../../shared/params_gen.h"
#include "../hipfft_params.h"
#include <algorithm>
#include <gtest/gtest.h>
#include <hip/hip_runtime_api.h>
#include <optional>
extern fft_params::fft_mp_lib mp_lib;
extern int mp_ranks;
static const std::vector<std::vector<size_t>> multi_gpu_sizes = {
{128, 256},
{64, 128, 256},
};
enum SplitType
{
// split both input and output on slow FFT dimension
SLOW_INOUT,
// split only input on slow FFT dimension, output is not split
SLOW_IN,
// split only output on slow FFT dimension, input is not split
SLOW_OUT,
// split input on slow FFT dimension, and output on fast FFT dimension
SLOW_IN_FAST_OUT,
// 3D pencil decomposition - one dimension is contiguous on input
// and another dimension contiguous on output, remaining dims are
// both split
PENCIL_3D,
};
std::vector<fft_params> param_generator_multi_gpu(const std::optional<SplitType> type)
{
int localDeviceCount = 0;
(void)hipGetDeviceCount(&localDeviceCount);
// if we have an explicit split of data on the user side, we need
// to use the multiprocessing API
if(type)
{
if(mp_lib == fft_params::fft_mp_lib_none)
return {};
}
// data is not explicitly split up, that means the library is
// asked to do the split. We need multiple GPUs to do this.
else if(localDeviceCount < 2)
return {};
static const std::vector<std::vector<size_t>> stride_range = {{1}};
auto params_complex = param_generator_complex(test_prob,
multi_gpu_sizes,
precision_range_sp_dp,
{1, 10},
stride_generator(stride_range),
stride_generator(stride_range),
{{0, 0}},
{{0, 0}},
{fft_placement_inplace, fft_placement_notinplace},
false);
auto params_real = param_generator_real(test_prob,
multi_gpu_sizes,
precision_range_sp_dp,
{1, 10},
stride_generator(stride_range),
stride_generator(stride_range),
{{0, 0}},
{{0, 0}},
{fft_placement_notinplace},
false);
std::vector<fft_params> all_params;
auto distribute_params = [=, &all_params](const std::vector<fft_params>& params) {
for(auto& p : params)
{
// test library splitting
if(!type)
{
auto param_multi = p;
// for single-batch, cuFFT only allows in-place
if(p.nbatch == 1 && p.placement == fft_placement_notinplace)
continue;
param_multi.multiGPU = std::min(static_cast<int>(p.nbatch), localDeviceCount);
all_params.emplace_back(std::move(param_multi));
}
else
{
// the API only allows for batch-1 multi-process FFTs
if(p.nbatch > 1)
continue;
// user-specified split
int brickCount = mp_ranks;
// start with all-ones in grids
std::vector<unsigned int> input_grid(p.length.size() + 1, 1);
std::vector<unsigned int> output_grid(p.length.size() + 1, 1);
auto p_dist = p;
switch(*type)
{
case SLOW_INOUT:
input_grid[1] = brickCount;
output_grid[1] = brickCount;
break;
case SLOW_IN:
// this type only specifies input field and no output
// field, but multi-process transforms require both
// fields.
if(mp_lib != fft_params::fft_mp_lib_none)
continue;
input_grid[1] = brickCount;
break;
case SLOW_OUT:
// this type only specifies output field and no input
// field, but multi-process transforms require both
// fields.
if(mp_lib != fft_params::fft_mp_lib_none)
continue;
output_grid[1] = brickCount;
break;
case SLOW_IN_FAST_OUT:
// requires at least rank-2 FFT
if(p.length.size() < 2)
continue;
input_grid[1] = brickCount;
output_grid.back() = brickCount;
break;
case PENCIL_3D:
// need at least 2 bricks per split dimension, or 4 devices.
// also needs to be a 3D problem.
if(brickCount < 4 || p.length.size() != 3)
continue;
// make fast dimension contiguous on input
input_grid[1] = static_cast<unsigned int>(sqrt(brickCount));
input_grid[2] = brickCount / input_grid[1];
// make middle dimension contiguous on output
output_grid[1] = input_grid[1];
output_grid[3] = input_grid[2];
break;
}
p_dist.mp_lib = mp_lib;
p_dist.distribute_input(localDeviceCount, input_grid);
p_dist.distribute_output(localDeviceCount, output_grid);
// "placement" flag is meaningless if exactly one of
// input+output is a field. So just add those cases if
// the flag is "out-of-place", since "in-place" is
// exactly the same test case.
if(p_dist.placement == fft_placement_inplace
&& p_dist.ifields.empty() != p_dist.ofields.empty())
continue;
// in-place transforms require identical input/output layouts
if(p.placement == fft_placement_inplace && input_grid != output_grid)
continue;
all_params.push_back(std::move(p_dist));
}
}
};
distribute_params(params_complex);
distribute_params(params_real);
return all_params;
}
// split both input and output on slowest FFT dim
INSTANTIATE_TEST_SUITE_P(multi_gpu_slowest_dim,
accuracy_test,
::testing::ValuesIn(param_generator_multi_gpu(SLOW_INOUT)),
accuracy_test::TestName);
// split slowest FFT dim only on input, or only on output
INSTANTIATE_TEST_SUITE_P(multi_gpu_slowest_input_dim,
accuracy_test,
::testing::ValuesIn(param_generator_multi_gpu(SLOW_IN)),
accuracy_test::TestName);
INSTANTIATE_TEST_SUITE_P(multi_gpu_slowest_output_dim,
accuracy_test,
::testing::ValuesIn(param_generator_multi_gpu(SLOW_OUT)),
accuracy_test::TestName);
// split input on slowest FFT and output on fastest, to minimize data
// movement (only makes sense for rank-2 and higher FFTs)
INSTANTIATE_TEST_SUITE_P(multi_gpu_slowin_fastout,
accuracy_test,
::testing::ValuesIn(param_generator_multi_gpu(SLOW_IN_FAST_OUT)),
accuracy_test::TestName);
// 3D pencil decompositions
INSTANTIATE_TEST_SUITE_P(multi_gpu_3d_pencils,
accuracy_test,
::testing::ValuesIn(param_generator_multi_gpu(PENCIL_3D)),
accuracy_test::TestName);
// library-decided splits
INSTANTIATE_TEST_SUITE_P(multi_gpu,
accuracy_test,
::testing::ValuesIn(param_generator_multi_gpu({})),
accuracy_test::TestName);
|