| 148 | } |
| 149 | |
| 150 | void TestSampleMeanDistributed(Context const* ctx) { |
| 151 | std::size_t m{32}, n{16}; |
| 152 | auto device = ctx->Device(); |
| 153 | std::int32_t n_workers = |
| 154 | device.IsCPU() ? std::min(4u, std::thread::hardware_concurrency()) : curt::AllVisibleGPUs(); |
| 155 | collective::TestDistributedGlobal(n_workers, [m, n, device, n_workers] { |
| 156 | auto rank = collective::GetRank(); |
| 157 | Context ctx = device.IsCUDA() ? MakeCUDACtx(DistGpuIdx()) : Context{}; |
| 158 | collective::GetWorkerLocalThreads(collective::GetWorldSize(), &ctx); |
| 159 | linalg::Matrix<float> data({m, n}, ctx.Device()); |
| 160 | auto h_data = data.HostView(); |
| 161 | for (std::size_t i = 0; i < m; ++i) { |
| 162 | for (std::size_t j = 0; j < n; ++j) { |
| 163 | h_data(i, j) = i + (m * rank) + j; |
| 164 | } |
| 165 | } |
| 166 | linalg::Vector<float> mean; |
| 167 | SampleMean(&ctx, false, data, &mean); |
| 168 | ASSERT_EQ(mean.Size(), n); |
| 169 | double total = n_workers * m; |
| 170 | for (std::size_t i = 0; i < n; ++i) { |
| 171 | ASSERT_EQ(mean(i), (i + total - 1.0 + i) * total / 2.0 / total); |
| 172 | } |
| 173 | }); |
| 174 | } |
| 175 | |
| 176 | void TestWeightedSampleMean(Context const* ctx) { |
| 177 | std::size_t m{32}, n{16}; |
no test coverage detected