| 280 | } |
| 281 | |
| 282 | std::pair<std::vector<std::string>, std::string> MakeArrayInterfaceBatch( |
| 283 | HostDeviceVector<float> const* storage, std::size_t n_samples, bst_feature_t n_features, |
| 284 | std::size_t batches, DeviceOrd device) { |
| 285 | std::vector<std::string> result(batches); |
| 286 | std::vector<Json> objects; |
| 287 | |
| 288 | size_t const rows_per_batch = n_samples / batches; |
| 289 | |
| 290 | auto make_interface = [storage, device, n_features](std::size_t offset, std::size_t rows) { |
| 291 | Json array_interface{Object()}; |
| 292 | array_interface["data"] = std::vector<Json>(2); |
| 293 | if (device.IsCUDA()) { |
| 294 | array_interface["data"][0] = |
| 295 | Integer(reinterpret_cast<int64_t>(storage->DevicePointer() + offset)); |
| 296 | array_interface["stream"] = Null{}; |
| 297 | } else { |
| 298 | array_interface["data"][0] = |
| 299 | Integer(reinterpret_cast<int64_t>(storage->HostPointer() + offset)); |
| 300 | } |
| 301 | |
| 302 | array_interface["data"][1] = Boolean(false); |
| 303 | |
| 304 | array_interface["shape"] = std::vector<Json>(2); |
| 305 | array_interface["shape"][0] = rows; |
| 306 | array_interface["shape"][1] = n_features; |
| 307 | |
| 308 | array_interface["typestr"] = String("<f4"); |
| 309 | array_interface["version"] = 3; |
| 310 | return array_interface; |
| 311 | }; |
| 312 | |
| 313 | auto j_interface = make_interface(0, n_samples); |
| 314 | size_t offset = 0; |
| 315 | for (size_t i = 0; i < batches - 1; ++i) { |
| 316 | objects.emplace_back(make_interface(offset, rows_per_batch)); |
| 317 | offset += rows_per_batch * n_features; |
| 318 | } |
| 319 | |
| 320 | size_t const remaining = n_samples - offset / n_features; |
| 321 | CHECK_LE(offset, n_samples * n_features); |
| 322 | objects.emplace_back(make_interface(offset, remaining)); |
| 323 | |
| 324 | for (size_t i = 0; i < batches; ++i) { |
| 325 | Json::Dump(objects[i], &result[i]); |
| 326 | } |
| 327 | |
| 328 | std::string interface_str; |
| 329 | Json::Dump(j_interface, &interface_str); |
| 330 | return {result, interface_str}; |
| 331 | } |
| 332 | |
| 333 | std::pair<std::vector<std::string>, std::string> RandomDataGenerator::GenerateArrayInterfaceBatch( |
| 334 | HostDeviceVector<float>* storage, size_t batches) const { |
no test coverage detected