Session
- class lluvia.core.Session
- compileComputeNode(self, ports, shaderCode, functionName='main', builderName='', localSize=(1, 1, 1), gridSize=(1, 1, 1), includeDirs=None, compileFlags=['-Werror'], includeGlslLibrary=True)
Compiles a ComputeNode from GLSL shader code.
This method assumes that glslc command is avialable in the system.
Parameters
- portslist of PortDescriptor.
List of port descriptors the compute node receives.
- shaderCodefile or str.
If file, it must contain the GLSL code of the shader to compile. The file is not closed during the execution of this method.
If str, it must be valid GLSL code. A temporal file is created and its path is passed to glslc for compilation.
- functionNamestr. Defaults to ‘main’.
Function name whitin the shader the compute node will execute.
- builderNamestr. Defaults to ‘’ (empty string).
Builder name associated to this node.
- localSizelist or tuple of length 3. Defaults to (1, 1, 1).
Local group size for each XYZ dimension. Each value must be greater or equal to 1.
- gridSizelist or tuple of length 3. Defaults to (1, 1, 1).
Grid size for each XYZ dimension. The grid size defines the number of local groups in each dimension. Each value must be greater or equal to 1.
- includeDirslist of strings. Defaults to None.
List of include directories to pass to glslc through -I flag.
- compileFlagslist of strings. Defaults to [‘-Werror’].
Extra compile flags to pass to glslc.
- includeGlslLibrarybool defaults to True.
Whether or not the standard Lluvia GLSL library embedded in the Python package should be included (using -I).
Returns
- nodelluvia.ComputeNode.
Compiled node.
Raises
- RuntimeError
If the compilation fails.
See also
compileProgram : Compiles a Program from GLSL shader code.
- compileProgram(self, shaderCode, includeDirs=None, compileFlags=['-Werror'], includeGlslLibrary=True)
Compiles a Program from GLSL shader code.
This method assumes that glslc command is avialable in the system.
Parameters
- shaderCodefile or str.
If file, it must contain the GLSL code of the shader to compile. The file is not closed during the execution of this method.
If str, it must be valid GLSL code. A temporal file is created and its path is passed to glslc for compilation.
- includeDirslist of strings. Defaults to None.
List of include directories to pass to glslc through -I flag.
- compileFlagslist of strings. Defaults to [‘-Werror’].
Extra compile flags to pass to glslc.
- includeGlslLibrarybool defaults to True.
Whether or not the standard Lluvia GLSL library embedded in the Python package should be included (using -I).
Returns
- programlluvia.Program.
Compiled program.
Raises
- RuntimeError
If the compilation fails.
- createCommandBuffer(self)
Creates a command buffer object.
Command buffers are used to record commands to be executed by the device. Once the recording finishes, the command buffer can be sent for execution using the run method.
Raises
- RuntimeError
If the command buffer cannot be created.
- createComputeNode(self, desc)
Creates a ComputeNode from a given descriptor or builder name.
Parameters
- descstring or lluvia.ComputeNodeDescriptor
If string, denotes the builder name used to create the ComputeNodeDescriptor for this node. Otherwise, a valid lluvia.ComputeNodeDescriptor must be provided.
Returns
node : lluvia.ComputeNode
Raises
- RuntimeError
If desc is a string and the node builder is not found in the registry.
- ValueError
If desc type is not string nor ComputeNodeDescriptor.
- createComputeNodeDescriptor(self, unicode builderName)
Creates a ComputeNodeDescriptor from its name in the registry.
Parameters
- builderNamestring.
Name of the builder.
Returns
- desclluvia.ComputeNodeDescriptor.
The descriptor
Raises
- RuntimeError
If builderName is not in the registry.
- createContainerNode(self, desc)
Creates a ComputeNode from a given descriptor or builder name.
Parameters
- descstring or lluvia.ContainerNodeDescriptor
If string, denotes the builder name used to create the ContainerNodeDescriptor for this node. Otherwise, a valid lluvia.ContainerNodeDescriptor must be provided.
Returns
node : lluvia.ComputeNode
Raises
- RuntimeError
If desc is a string and the node builder is not found in the registry.
- ValueError
If desc type is not string nor ContainerNodeDescriptor.
- createContainerNodeDescriptor(self, unicode builderName)
Creates a ContainerNodeDescriptor from its name in the registry.
Parameters
- builderNamestring.
Name of the builder.
Returns
- desclluvia.ContainerNodeDescriptor.
The descriptor
Raises
- RuntimeError
If builderName is not in the registry.
- createMemory(self, flags=ll_memory.MemoryPropertyFlagBits.DeviceLocal, uint64_t pageSize=33554432, bool exactFlagsMatch=False)
Creates a new memory.
- ```
import lluvia as ll
session = ll.createSession() memory = session.createMemory([ll.MemoryPropertyFlagBits.HostVisible,
ll.MemoryPropertyFlagBits.HostCoherent],
4096, False)
The flags parameter can contain one string or a list of strings specifying the memory property flags the new memory will be created with. The possible values are defined in lluvia.MemoryPropertyFlagBits:
DeviceLocal
HostCached
HostCoherent
HostVisible
LazilyAllocated
See https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkMemoryPropertyFlagBits for more information.
Parameters
- flagsstring or list of strings. Defaults to ‘DeviceLocal’
Flags to determine the type of memory to be created. Each flag should be one of the strings in lluvia.MemoryPropertyFlags.
- pageSizeuint64_t. Defaults to 32MB (33554432L).
The size in bytes of each page the new memory object will allocate when there is no space for creating new objects.
- exactFlagsMatchbool defaults to False.
Tells whether or not flags should match exactly one of the values in lluvia.Session.getSupportedMemoryFlags() or if it is enough that it contains at least the flags values.
Returns
memory : a new lluvia.Memory object.
See also
- getSupportedMemoryPropertyFlagsReturns the supported memory property
flags for creating memories in this session.
- createProgram(self, unicode path)
Creates a Program object reading the SPIR-V code from a given file.
Parameters
- pathstring
path to the file where the SPIR-V code is stored.
Returns
program : lluvia.Program
Raises
- IOError
If there is any problem reading the file at the given path.
- deviceDescriptor
- getDeviceMemory(self)
Returns a memory object that is DEVICE_LOCAL. This memory can be used to create buffers and images to pass to shaders.
Returns
mem : ll.Memory
- getGoodComputeLocalShape(self, ComputeDimension dimensions)
Returns the suggested local grid shape for compute nodes given the number of dimensions.
The local shape depends on the underlying device used.
Parameters
- dimensionsComputeDimension
The number of compute dimensions
Returns
- localShape3-tuple
The suggested local shape.
- getHostMemory(self)
Returns a memory object that is HOST_LOCAL and HOST_COHERENT. This memory can be used to create uniform buffers to pass to shaders.
Returns
mem : ll.Memory
- getNodeBuilderDescriptors(self)
Gets the node builder descriptors currently registered.
Returns
- descriptorslist of NodeBuilderDescriptor
The list of descriptors.
- getProgram(self, unicode name)
Returns a program from the registry
Parameters
- namestring.
Name of the program.
Returns
- programlluvia.Program
The program.
Raises
- KeyError
If the program does not exists in the registry
- getSupportedMemoryPropertyFlags(self)
Returns the supported memory property flags for creating memories in this session.
The length of the returned vector equals the number of Vulkan memory types available for the physical device this session was created from.
See https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkMemoryPropertyFlagBits for more information.
Returns
- supportedMemoryFlagslist of string lists
The supported memory property flags combinations supported by this session.
- hasReceivedVulkanWarningMessages(self)
Tells whether or not this session has triggered Vulkan warning messages
Returns
- bbool
Whether or not Vulkan warning messages have been received
- help(self, unicode builderName)
Returns the help string of a given node builder.
Parameters
- builderNamestr
The builder name
Returns
- helpStringstr
The help string.
- loadLibrary(self, unicode filename)
Loads a library made of SPIR-V shader code and Lua scripts.
Parameters
- filenamestring
Path to the library file. The file must be a valid zip archive.
Raises
- RuntimeError
If there is problem reading the library file.
- script(self, unicode code)
Runs a Lua script in the session’s interpreter
Parameters
- codestring
The Lua code.
- scriptFile(self, unicode filename)
Read and run a Lua script file in the session’s interpreter
Parameters
- codestring
Path to the script file.
- setProgram(self, unicode name, program)
Sets a program into the registry with a given name
Parameters
- namestring
The name of the program in the registry.
- programstring or lluvia.Program.
If string, this parameter denotes a path to a SPIR-V file used to build the program. This is equivalent to call session.setProgram(name, session.createProgram(program))
Raises
- ValueError
If program’s type is not string nor lluvia.Program