Main Content

setConstantMemory

Set some constant memory on GPU

Description

setConstantMemory(kern,sym,val) sets the constant memory in the CUDA kernel kern with symbol name sym to contain the data in val. val can be any numeric array, including a gpuArray. The function errors if the named symbol does not exist or if it is not big enough to contain the specified data. You can partially fill a constant.

There is no automatic data-type conversion for constant memory, so you must make sure that the supplied data is of the correct type for the constant memory symbol that you are filling.

example

setConstantMemory(kern,sym1,val1,sym2,val2,...) sets multiple constant symbols.

example

Examples

collapse all

If KERN represents a CUDA kernel whose CU file contains these includes and constant definitions:

#include "tmwtypes.h"
__constant__ int32_t N1;
__constant__ int N2; // Assume 'int' is 32 bits
__constant__ double CONST_DATA[256];

You can fill these with MATLAB® data by running these commands:

KERN = parallel.gpu.CUDAKernel(ptxFile,cudaFile);
setConstantMemory(KERN,'N1',int32(10));
setConstantMemory(KERN,'N2',int32(10));
setConstantMemory(KERN,'CONST_DATA',1:10);

Alternatively, you can run this command:

setConstantMemory(KERN,'N1',int32(10),'N2',int32(10),'CONST_DATA',1:10);

Input Arguments

collapse all

CUDA kernel, specified as a parallel.gpu.CUDAKernel object.

Symbol name of the constant memory of the CUDA kernel, specified as a character vector. The function errors if the named symbol does not exist or if it is not big enough to contain the specified data

Data to assign to a specific constant memory, specified as a numeric array or a gpuArray object.

Version History

Introduced in R2012a