| 201 | } |
| 202 | |
| 203 | void TestWeightedSampleMeanDistributed(Context const* ctx) { |
| 204 | std::size_t m{32}, n{16}; |
| 205 | auto device = ctx->Device(); |
| 206 | std::int32_t n_workers = |
| 207 | device.IsCPU() ? std::min(4u, std::thread::hardware_concurrency()) : curt::AllVisibleGPUs(); |
| 208 | |
| 209 | collective::TestDistributedGlobal(n_workers, [m, n, device, n_workers] { |
| 210 | auto rank = collective::GetRank(); |
| 211 | Context ctx = device.IsCUDA() ? MakeCUDACtx(DistGpuIdx()) : Context{}; |
| 212 | collective::GetWorkerLocalThreads(collective::GetWorldSize(), &ctx); |
| 213 | linalg::Matrix<float> data({m, n}, ctx.Device()); |
| 214 | auto h_data = data.HostView(); |
| 215 | for (std::size_t i = 0; i < m; ++i) { |
| 216 | for (std::size_t j = 0; j < n; ++j) { |
| 217 | h_data(i, j) = i + (m * rank) + j; |
| 218 | } |
| 219 | } |
| 220 | HostDeviceVector<float> w{m, 1.0f, ctx.Device()}; |
| 221 | linalg::Vector<float> mean; |
| 222 | WeightedSampleMean(&ctx, false, data, w, &mean); |
| 223 | ASSERT_EQ(mean.Size(), n); |
| 224 | double total = n_workers * m; |
| 225 | for (std::size_t i = 0; i < n; ++i) { |
| 226 | ASSERT_EQ(mean(i), (i + total - 1.0 + i) * total / 2.0 / total); |
| 227 | } |
| 228 | }); |
| 229 | } |
| 230 | } // namespace |
| 231 | |
| 232 | TEST(Stats, SampleMean) { |
no test coverage detected