| 381 | } |
| 382 | |
| 383 | int main() |
| 384 | { |
| 385 | // Initialize a random array of chars |
| 386 | const size_t input_buffer_len = 1000000; |
| 387 | std::vector<uint8_t> uncompressed_data(input_buffer_len); |
| 388 | |
| 389 | std::mt19937 random_gen(42); |
| 390 | |
| 391 | // char specialization of std::uniform_int_distribution is |
| 392 | // non-standard, and isn't available on MSVC, so use short instead, |
| 393 | // but with the range limited, and then cast below. |
| 394 | std::uniform_int_distribution<short> uniform_dist(0, 255); |
| 395 | for (size_t ix = 0; ix < input_buffer_len; ++ix) { |
| 396 | uncompressed_data[ix] = static_cast<uint8_t>(uniform_dist(random_gen)); |
| 397 | } |
| 398 | |
| 399 | uint8_t* device_input_ptrs; |
| 400 | CUDA_CHECK(cudaMalloc(&device_input_ptrs, input_buffer_len)); |
| 401 | CUDA_CHECK(cudaMemcpy(device_input_ptrs, uncompressed_data.data(), input_buffer_len, cudaMemcpyDefault)); |
| 402 | |
| 403 | // Four roundtrip examples |
| 404 | decomp_compressed_with_manager_factory_example(device_input_ptrs, input_buffer_len); |
| 405 | decomp_compressed_with_manager_factory_with_checksums(device_input_ptrs, input_buffer_len); |
| 406 | comp_decomp_with_single_manager(device_input_ptrs, input_buffer_len); |
| 407 | comp_decomp_with_single_manager_with_checksums(device_input_ptrs, input_buffer_len); |
| 408 | |
| 409 | CUDA_CHECK(cudaFree(device_input_ptrs)); |
| 410 | |
| 411 | // Multi buffer example |
| 412 | const size_t num_buffers = 10; |
| 413 | |
| 414 | std::vector<uint8_t*> gpu_buffers(num_buffers); |
| 415 | std::vector<size_t> input_buffer_lengths(num_buffers); |
| 416 | |
| 417 | std::vector<std::vector<uint8_t>> uncompressed_buffers(num_buffers); |
| 418 | for (size_t ix_buffer = 0; ix_buffer < num_buffers; ++ix_buffer) { |
| 419 | uncompressed_buffers[ix_buffer].resize(input_buffer_len); |
| 420 | for (size_t ix_byte = 0; ix_byte < input_buffer_len; ++ix_byte) { |
| 421 | uncompressed_buffers[ix_buffer][ix_byte] = static_cast<uint8_t>(uniform_dist(random_gen)); |
| 422 | } |
| 423 | CUDA_CHECK(cudaMalloc(&gpu_buffers[ix_buffer], input_buffer_len)); |
| 424 | CUDA_CHECK(cudaMemcpy(gpu_buffers[ix_buffer], uncompressed_buffers[ix_buffer].data(), input_buffer_len, cudaMemcpyDefault)); |
| 425 | input_buffer_lengths[ix_buffer] = input_buffer_len; |
| 426 | } |
| 427 | |
| 428 | multi_comp_decomp_example(gpu_buffers, input_buffer_lengths); |
| 429 | multi_comp_decomp_example_comp_config(gpu_buffers, input_buffer_lengths); |
| 430 | |
| 431 | for (size_t ix_buffer = 0; ix_buffer < num_buffers; ++ix_buffer) { |
| 432 | CUDA_CHECK(cudaFree(gpu_buffers[ix_buffer])); |
| 433 | } |
| 434 | return 0; |
| 435 | } |
nothing calls this directly
no test coverage detected