cuda-kat
CUDA kernel author's tools
Typedefs | Functions
string.cuh File Reference

CUDA device-side versions of the C standard library string operations. More...

#include <kat/on_device/common.cuh>
#include <kat/detail/execution_space_specifiers.hpp>

Typedefs

using kat::c_std_lib::size_t = std::size_t
 

Functions

__device__ int kat::c_std_lib::strcmp (const char *lhs, const char *rhs)
 Lexicographically compares two nul-terminated strings. More...
 
__device__ int kat::c_std_lib::strncmp (const char *lhs, const char *rhs, size_t n)
 Lexicographically compares two nul-terminated strings - but no farther than their n'th character. More...
 
__device__ int kat::c_std_lib::memcmp (const void *lhs, const void *rhs, size_t n)
 Lexicographically compare two equal-length sequences of bytes. More...
 
__device__ char * kat::c_std_lib::strcpy (char *dst, const char *src)
 Copy a nul-terminated string from one location to another. More...
 
__device__ char * kat::c_std_lib::strncpy (char *dst, const char *src, size_t n)
 Copy a nul-terminated string from one location to another - but always write no more and no less than a fixed number of characters. More...
 
__device__ std::size_t kat::c_std_lib::strlen (const char *s)
 determines the length of a nul-terminated string More...
 
__device__ char * kat::c_std_lib::strcat (char *dest, const char *src)
 concatenates one string after another, in-place. More...
 
__device__ char * kat::c_std_lib::strncat (char *dest, const char *src, size_t n)
 concatenates one string after another, in-place - but appending no more than a fixed number of characters to the string at the destination. More...
 
__device__ void * kat::c_std_lib::memcpy (void *__restrict__ destination, const void *__restrict__ source, size_t size)
 copies a stretch of memory from one location to another More...
 
__device__ void * kat::c_std_lib::memset (void *destination, int c, size_t size)
 set a sequence of bytes in memory to a fixed value More...
 
__device__ void * kat::c_std_lib::memchr (const void *s, int c, size_t n)
 locate a byte with a specified value in a sequence of bytes in memory. More...
 
__device__ char * kat::c_std_lib::strchr (const char *s, int c)
 Search for a character within a nul-terminated string. More...
 
__device__ char * kat::c_std_lib::strrchr (const char *s, int c)
 same as std::strchr , except that the search begins at the end of the string More...
 
__device__ char * kat::c_std_lib::strpbrk (const char *s, const char *accept)
 
__device__ size_t kat::c_std_lib::strspn (const char *s, const char *accept)
 
__device__ size_t kat::c_std_lib::strcspn (const char *s, const char *reject)
 
__device__ char * kat::c_std_lib::strstr (const char *haystack, const char *needle)
 
__device__ char * kat::c_std_lib::strrstr (const char *haystack, const char *needle)
 

Detailed Description

CUDA device-side versions of the C standard library string operations.

Note
The implementations are not intended to be particularly speedy - merely functional. In particular - you are advised to only use this when each thread is working on its own string.
unimplemented functions: strcoll, strxfrm (these require a locale); strerror (errno errors are not generated by device-side code); strtok (not reentrant)
The implementations are not actually C functions; I've put them in C++ namespaces. This choice could be changed if users demand it.

Function Documentation

§ memchr()

__device__ void* kat::c_std_lib::memchr ( const void *  s,
int  c,
size_t  n 
)
inline

locate a byte with a specified value in a sequence of bytes in memory.

Parameters
sbeginning of the sequence of bytes at which to begin the search
cvalue to search for; must be in the range of 0 .. (1 << CHAR_BIT) - 1 .
nnumber of bytes to search for the desired value
Returns
address of the first byte in the sequence with the value c, within the sequence starting at s, or nullptr if none of the first n bytes have that value.

§ memcmp()

__device__ int kat::c_std_lib::memcmp ( const void *  lhs,
const void *  rhs,
size_t  n 
)
inline

Lexicographically compare two equal-length sequences of bytes.

Note
similar to strncmp, except that the comparison does not stop with 0-valued bytes.
Parameters
lhs
rhs
nThe length of each sequence of bytes
Returns
a negative value if lhs > rhs, zero if lhs == rhs and a positive value if lhs < rhs

§ memcpy()

__device__ void* kat::c_std_lib::memcpy ( void *__restrict__  destination,
const void *__restrict__  source,
size_t  size 
)
inline

copies a stretch of memory from one location to another

Note
the two regions - size bytes at source, size bytes at destination - must be disjoint
Parameters
destinationbeginning of the target region
sourcebeginning of the source region
sizethe length of the memory region to copy

§ memset()

__device__ void* kat::c_std_lib::memset ( void *  destination,
int  c,
size_t  size 
)
inline

set a sequence of bytes in memory to a fixed value

Parameters
destinationbeginning of the sequence of bytes to set
cvalue to which to set the bytes; must be in the range of 0 .. (1 << CHAR_BIT) - 1 .
sizenumber of bytes to set to value c.

§ strcat()

__device__ char* kat::c_std_lib::strcat ( char *  dest,
const char *  src 
)
inline

concatenates one string after another, in-place.

Parameters
destThe target location for both string (after concatenation)
srcThe string to be concatenated.
Returns
A pointer to dest, after it has gotten a copy of src concatenated at its end.

§ strchr()

__device__ char* kat::c_std_lib::strchr ( const char *  s,
int  c 
)
inline

Search for a character within a nul-terminated string.

Parameters
sThe string to search
cA character value to search for
Returns
address of the first character with the value c within string s, or nullptr if no character of s equals c .

§ strcmp()

__device__ int kat::c_std_lib::strcmp ( const char *  lhs,
const char *  rhs 
)
inline

Lexicographically compares two nul-terminated strings.

Note
comparison is not locale-specific
Returns
a negative value if lhs > rhs, zero if lhs == rhs and a positive value if lhs < rhs.

§ strcpy()

__device__ char* kat::c_std_lib::strcpy ( char *  dst,
const char *  src 
)
inline

Copy a nul-terminated string from one location to another.

Returns
the target location (which, after execution, should contain a copy of the string — when accessed from the calling thread or after appropriate synchronization).

§ strlen()

__device__ std::size_t kat::c_std_lib::strlen ( const char *  s)
inline

determines the length of a nul-terminated string

Returns
The length of the string, i.e. the number of characters before the terminating '\0' (nul) character.

§ strncat()

__device__ char* kat::c_std_lib::strncat ( char *  dest,
const char *  src,
size_t  n 
)
inline

concatenates one string after another, in-place - but appending no more than a fixed number of characters to the string at the destination.

Parameters
destThe target location for both string (after concatenation)
srcThe string to be concatenated.
nMaximum number of characters used from the source string
Returns
A pointer to dest, after it has gotten a copy of src concatenated at its end - or the first n characters of src followed with a terminating '\0' (nul).

§ strncmp()

__device__ int kat::c_std_lib::strncmp ( const char *  lhs,
const char *  rhs,
size_t  n 
)
inline

Lexicographically compares two nul-terminated strings - but no farther than their n'th character.

Note
comparison is not locale-specific.
Returns
a negative value if lhs > rhs, zero if lhs == rhs and a positive value if lhs < rhs - but with the comparisons ignoring everything after the n'th character of each of the strings, so - if they differ after then n'th character, zero is returned.

§ strncpy()

__device__ char* kat::c_std_lib::strncpy ( char *  dst,
const char *  src,
size_t  n 
)
inline

Copy a nul-terminated string from one location to another - but always write no more and no less than a fixed number of characters.

Parameters
dstcopy destination
srcstring to copy from
nthe number of characters to write at the destination
Returns
the target location (which, after execution, should contain a copy of the string or the first n characters thereof — when accessed from the calling thread or after appropriate synchronization).

§ strrchr()

__device__ char* kat::c_std_lib::strrchr ( const char *  s,
int  c 
)
inline

same as std::strchr , except that the search begins at the end of the string

Note
If c is '\0', it will match the nul character at the end of the string.