cuDDL
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
cuddl::result_file Class Reference

Writes search results to files while the GPUs search on. More...

Public Member Functions

Result< void > write (batch_result_tile const &tile, cuda::stream_ref stream)
 Downloads tile, whose results stream orders, and queues it for writing.
 
Result< void > write (replica_tile const &tile)
 
Result< void > write (std::span< batch_search_result const > rows)
 Queues results already on the host, such as each genome's top-k neighbours.
 
Result< void > finish ()
 Writes everything queued and closes the files, flushing them to storage first if the file is durable.
 
result_file_statistics statistics () const
 

Static Public Member Functions

static std::vector< std::filesystem::path > files (std::filesystem::path const &path, unsigned streams)
 The files a result file with streams streams writes for path.
 
static Result< result_file > open (std::filesystem::path const &path, result_file_options options={})
 Creates or truncates the files for path.
 

Detailed Description

Writes search results to files while the GPUs search on.

Pass every tile a search delivers to write, from its on_tile callback. A write copies the tile to pinned host memory, or in result_format::similarity converts it on the GPU first, and returns; a thread of the file's expands it into records on every core and writes them, bypassing the page cache where the file system allows. Each stream that delivers tiles gets two host buffers, so its next tile downloads while the last one is written; a write waits only when both are still being written. Tiles reach the file in the order their writes finish downloading, which is the search order when callbacks run one at a time. The buffers are freed on those streams, so call finish, or destroy the file, while they live.

auto file = CUDDL_TRY(cuddl::result_file::open("pairs.bin"));
CUDDL_TRY(group.search_all_to_all([&](cuddl::replica_tile const& tile) {
CUDDL_UNWRAP(file.write(tile));
}));
CUDDL_TRY(file.finish());
static Result< result_file > open(std::filesystem::path const &path, result_file_options options={})
Creates or truncates the files for path.
#define CUDDL_TRY(expr)
Propagates a cuddl::Result failure from the enclosing function (GNU statement expression).
Definition error.hpp:225
One all-to-all tile as a replicated_database search delivers it.

Definition at line 112 of file result_file.cuh.

Member Function Documentation

◆ files()

static std::vector< std::filesystem::path > cuddl::result_file::files ( std::filesystem::path const &  path,
unsigned  streams 
)
inlinestatic

The files a result file with streams streams writes for path.

Definition at line 116 of file result_file.cuh.

116 {
117 if (streams <= 1) return {path};
118 std::vector<std::filesystem::path> paths;
119 paths.reserve(streams);
120 for (unsigned s = 0; s < streams; ++s)
121 paths.emplace_back(path.string() + "." + std::to_string(s));
122 return paths;
123 }

◆ finish()

Result< void > cuddl::result_file::finish ( )
inline

Writes everything queued and closes the files, flushing them to storage first if the file is durable.

Reports the first error any write met.

Definition at line 158 of file result_file.cuh.

158 {
159 return state_->finish();
160 }

◆ open()

static Result< result_file > cuddl::result_file::open ( std::filesystem::path const &  path,
result_file_options  options = {} 
)
inlinestatic

Creates or truncates the files for path.

Definition at line 127 of file result_file.cuh.

127 {}) {
128 if (options.streams == 0) {
129 return Err(Error::invalid_argument("a result file needs at least one stream"));
130 }
131 result_file file;
132 try {
133 file.state_ = std::make_unique<state>(path, options);
134 } catch (std::exception const& error) {
135 return Err(Error::resource(error.what()));
136 }
137 return file;
138 }
cuda::std::unexpected< Error > Err(Error error)
Failure return; converts to any Result<T> via cuda::std::unexpected.
Definition error.hpp:176
static Error invalid_argument(std::string message)
Definition error.hpp:99
static Error resource(std::string message)
Definition error.hpp:103

◆ statistics()

result_file_statistics cuddl::result_file::statistics ( ) const
inline

Definition at line 162 of file result_file.cuh.

162 {
163 std::lock_guard lock(state_->mutex);
164 return state_->statistics;
165 }

◆ write() [1/3]

Result< void > cuddl::result_file::write ( batch_result_tile const &  tile,
cuda::stream_ref  stream 
)
inline

Downloads tile, whose results stream orders, and queues it for writing.

Thread-safe. The tile's device storage is free for reuse when it returns.

Definition at line 143 of file result_file.cuh.

143 {
144 return state_->write(tile, stream);
145 }
Here is the caller graph for this function:

◆ write() [2/3]

Result< void > cuddl::result_file::write ( replica_tile const &  tile)
inline

Definition at line 147 of file result_file.cuh.

147 {
148 return write(tile.tile, tile.stream);
149 }
Result< void > write(batch_result_tile const &tile, cuda::stream_ref stream)
Downloads tile, whose results stream orders, and queues it for writing.
__global__ size_t uint32_t const uint32_t const uint32_t uint32_t uint16_t uint32_t tile
Definition kernels.cuh:922
Here is the call graph for this function:

◆ write() [3/3]

Result< void > cuddl::result_file::write ( std::span< batch_search_result const >  rows)
inline

Queues results already on the host, such as each genome's top-k neighbours.

Definition at line 152 of file result_file.cuh.

152 {
153 return state_->write(rows);
154 }

The documentation for this class was generated from the following file: