gpu.cpp 0.1.0
 
Loading...
Searching...
No Matches
gpu::KernelCode Struct Reference

KernelCode is the representation of WGSL GPU code with template substitutions applied. It is a type around the code string with additional metadata for workgroup size and precision since they are specified in the WGSL code. Additionally, label and entryPoint are used by createKernel() to specify the label and entry point of the kernel. More...

#include <gpu.h>

Public Member Functions

 KernelCode (const std::string &pData="", size_t workgroupSize=256, NumType precision=kf32)
 Constructor to create a code object from a template string and optional workgroup size and precision.
 
 KernelCode (const std::string &pData, const Shape &workgroupSize={256, 1, 1}, NumType precision=kf32)
 Overload of the constructor to create a code object from a template string and workgroup size. Unlike the main factory function, this overload takes a single size_t workgroupSize parameter instead of a 3D shape for the workgroup size and instantiates a 3D shape with the workgroupSize in the x dimension and 1 in the y and z dimensions.
 

Public Attributes

std::string data
 
Shape workgroupSize
 
NumType precision = kf32
 
std::string label = "kernel"
 
std::string entryPoint = "main"
 

Detailed Description

KernelCode is the representation of WGSL GPU code with template substitutions applied. It is a type around the code string with additional metadata for workgroup size and precision since they are specified in the WGSL code. Additionally, label and entryPoint are used by createKernel() to specify the label and entry point of the kernel.

Definition at line 272 of file gpu.h.

Constructor & Destructor Documentation

◆ KernelCode() [1/2]

gpu::KernelCode::KernelCode ( const std::string & pData = "",
size_t workgroupSize = 256,
NumType precision = kf32 )
inline

Constructor to create a code object from a template string and optional workgroup size and precision.

Parameters
[in]pDataShader template string with placeholders
[in]workgroupSizeShape of the workgroup. Unlike tensor shapes which can be of arbitrary rank, workgroup size is always of rank 3 corresponding to x y and z. workgroupSize is stored as a field in the KernelCode instance that is returned by createShader().
[in]precisionData type precision to be substituted for {{precision}} in the WGSL code. As with workgroupSize, precision is stored as a field in the KernelCode instance that is returned by createShader().
KernelCode code = {kShaderText, {256, 1, 1}, kf32};
@ kf32
Definition gpu.h:185
KernelCode is the representation of WGSL GPU code with template substitutions applied....
Definition gpu.h:272

Definition at line 289 of file gpu.h.

291 : data(pData), workgroupSize({workgroupSize, 1, 1}),
293 if (precision == kf16) {
294 data = "enable f16;\n" + data;
295 }
296 replaceAll(data, "{{workgroupSize}}", toString({workgroupSize, 1, 1}));
297 replaceAll(data, "{{precision}}", toString(precision));
298 LOG(kDefLog, kTrace, "Shader code:\n%s", data.c_str());
299 }
static Logger kDefLog
Default logger for logging messages to stdout at the info level. Output stream and logging level for ...
Definition logging.h:64
void LOG(Logger &logger, int level, const char *message,...)
Log a message to the logger. If NDEBUG is defined in a source or as a compiler flag,...
Definition logging.h:34
std::string toString(NumType type)
Converts NumType to string.
Definition gpu.h:206
@ kf16
Definition gpu.h:184
@ kTrace
Definition logging.h:9
void replaceAll(std::string &str, const std::string &from, const std::string &to)
simple in-place string replacement helper function for substituting placeholders in a WGSL string tem...
Definition gpu.h:256
Shape workgroupSize
Definition gpu.h:326
std::string data
Definition gpu.h:325
NumType precision
Definition gpu.h:327

◆ KernelCode() [2/2]

gpu::KernelCode::KernelCode ( const std::string & pData,
const Shape & workgroupSize = {256, 1, 1},
NumType precision = kf32 )
inline

Overload of the constructor to create a code object from a template string and workgroup size. Unlike the main factory function, this overload takes a single size_t workgroupSize parameter instead of a 3D shape for the workgroup size and instantiates a 3D shape with the workgroupSize in the x dimension and 1 in the y and z dimensions.

Parameters
[in]pDataShader template string with placeholders
[in]workgroupSizeWorkgroup size in the x dimension
[in]precisionData type precision for the shader
KernelCode code = {kPuzzle1, 256, kf32};

Definition at line 317 of file gpu.h.

318 {256, 1, 1},
321 replaceAll(data, "{{workgroupSize}}", toString(workgroupSize));
322 replaceAll(data, "{{precision}}", toString(precision));
323 LOG(kDefLog, kInfo, "Shader code:\n%s", data.c_str());
324 }
NumType
Definition gpu.h:183
@ kInfo
Definition logging.h:9

Member Data Documentation

◆ data

std::string gpu::KernelCode::data

Definition at line 325 of file gpu.h.

◆ entryPoint

std::string gpu::KernelCode::entryPoint = "main"

Definition at line 329 of file gpu.h.

◆ label

std::string gpu::KernelCode::label = "kernel"

Definition at line 328 of file gpu.h.

◆ precision

NumType gpu::KernelCode::precision = kf32

Definition at line 327 of file gpu.h.

◆ workgroupSize

Shape gpu::KernelCode::workgroupSize

Definition at line 326 of file gpu.h.


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