Speclib  0.1.2
The library for writing better CUDA libraries
sp::StringBatch< CharT > Class Template Reference

A batch of strings which can be synchronised between host and device. More...

#include <StringBatch.hpp>

Public Member Functions

 StringBatch (const std::vector< std::string > &strings)
 Construct a StringBatch representing the given std::vector of strings. More...
 
StringViewBatch< __device const CharT, __device const sp::Vec< int, 2 > > deviceView (sp::Stream &s) const
 Get an immutable GPU-side view of this batch of strings, enqueuing a host->device copy on s if needed. More...
 
StringViewBatch< __device CharT, __device sp::Vec< int, 2 > > mutableDeviceView (sp::Stream &s)
 Get a mutable GPU-side view of this batch of strings, enqueuing a host->device copy on s if needed. More...
 
StringViewBatch< __device const CharT, __device const sp::Vec< int, 2 > > hostView (sp::Stream &s) const
 Get an immutable host-side view of this batch of strings, enqueuing a device->host copy on s if needed. More...
 
StringViewBatch< __device const CharT, __device const sp::Vec< int, 2 > > mutableHostView (sp::Stream &s)
 Get a mutable host-side view of this batch of strings, enqueuing a device->host copy on s if needed. More...
 

Detailed Description

template<typename CharT>
class sp::StringBatch< CharT >

A batch of strings which can be synchronised between host and device.

These are stored in contiguous memory with interstitial null bytes between adjacent strings (which are aligned for efficient retrieval of individual strings when necessary).

This provides a convenient way to allocate batches of strings and move them between host and device. The result is likely to be far more efficient than using a pile of floating sp::StringBatch objects.

This object is conceptually similar to sp::NomadicTensor. Calling APIs like hostView() or deviceView() gets you a sp::StringViewBatch on the target device, and enqueues a copy as necessary.

Template Parameters
CharTThe type of char to store.

Constructor & Destructor Documentation

◆ StringBatch()

template<typename CharT >
sp::StringBatch< CharT >::StringBatch ( const std::vector< std::string > &  strings)

Construct a StringBatch representing the given std::vector of strings.

The strings are copied into the newly-allocated buffers owned by this object. While this is a convenient way of initialising the host side of the buffer using strings present on the host, it is not optimally efficient. Each std::string allocates its own buffer. The most efficient approach would be to use one std::string, a bunch of std::string_views, and use a single memcpy to populate the host view of this object. Equivalently, sp::StringBuffer and sp::StringView could be used.

Parameters
stringsHost-side strings to initialise with.

Member Function Documentation

◆ deviceView()

template<typename CharT >
StringViewBatch< __device const CharT, __device const sp::Vec< int, 2 > > sp::StringBatch< CharT >::deviceView ( sp::Stream s) const

Get an immutable GPU-side view of this batch of strings, enqueuing a host->device copy on s if needed.

◆ hostView()

template<typename CharT >
StringViewBatch< __device const CharT, __device const sp::Vec< int, 2 > > sp::StringBatch< CharT >::hostView ( sp::Stream s) const

Get an immutable host-side view of this batch of strings, enqueuing a device->host copy on s if needed.

◆ mutableDeviceView()

template<typename CharT >
StringViewBatch< __device CharT, __device sp::Vec< int, 2 > > sp::StringBatch< CharT >::mutableDeviceView ( sp::Stream s)

Get a mutable GPU-side view of this batch of strings, enqueuing a host->device copy on s if needed.

◆ mutableHostView()

template<typename CharT >
StringViewBatch< __device const CharT, __device const sp::Vec< int, 2 > > sp::StringBatch< CharT >::mutableHostView ( sp::Stream s)

Get a mutable host-side view of this batch of strings, enqueuing a device->host copy on s if needed.