| 34 | constexpr int64_t kGpuNumber = 0; |
| 35 | |
| 36 | static void CudaBufferWriterBenchmark(benchmark::State& state, const int64_t total_bytes, |
| 37 | const int64_t chunksize, |
| 38 | const int64_t buffer_size) { |
| 39 | CudaDeviceManager* manager = nullptr; |
| 40 | ABORT_NOT_OK(CudaDeviceManager::Instance().Value(&manager)); |
| 41 | std::shared_ptr<CudaContext> context; |
| 42 | ABORT_NOT_OK(manager->GetContext(kGpuNumber).Value(&context)); |
| 43 | |
| 44 | std::shared_ptr<CudaBuffer> device_buffer; |
| 45 | ABORT_NOT_OK(context->Allocate(total_bytes).Value(&device_buffer)); |
| 46 | CudaBufferWriter writer(device_buffer); |
| 47 | |
| 48 | if (buffer_size > 0) { |
| 49 | ABORT_NOT_OK(writer.SetBufferSize(buffer_size)); |
| 50 | } |
| 51 | |
| 52 | std::shared_ptr<ResizableBuffer> buffer; |
| 53 | ASSERT_OK(MakeRandomByteBuffer(total_bytes, default_memory_pool(), &buffer)); |
| 54 | |
| 55 | const uint8_t* host_data = buffer->data(); |
| 56 | while (state.KeepRunning()) { |
| 57 | int64_t bytes_written = 0; |
| 58 | ABORT_NOT_OK(writer.Seek(0)); |
| 59 | while (bytes_written < total_bytes) { |
| 60 | int64_t bytes_to_write = std::min(chunksize, total_bytes - bytes_written); |
| 61 | ABORT_NOT_OK(writer.Write(host_data + bytes_written, bytes_to_write)); |
| 62 | bytes_written += bytes_to_write; |
| 63 | } |
| 64 | } |
| 65 | state.SetBytesProcessed(int64_t(state.iterations()) * total_bytes); |
| 66 | } |
| 67 | |
| 68 | static void Writer_Buffered(benchmark::State& state) { |
| 69 | // 128MB |
no test coverage detected