Lluvia
Session.h
Go to the documentation of this file.
1 
8 #ifndef LLUVIA_CORE_SESSION_H_
9 #define LLUVIA_CORE_SESSION_H_
10 
12 
13 #include <cstdint>
14 #include <map>
15 #include <memory>
16 #include <mutex>
17 #include <string>
18 #include <tuple>
19 #include <vector>
20 
27 #include "lluvia/core/types.h"
28 
29 namespace ll {
30 
31 namespace vulkan {
32  class Device;
33  class Instance;
34 } // namespace vulkan
35 
36 class Buffer;
37 class CommandBuffer;
38 class ComputeNode;
39 class ComputeNodeDescriptor;
40 class ContainerNode;
41 class ContainerNodeDescriptor;
42 class Duration;
43 class Image;
44 class Interpreter;
45 class Memory;
46 class Program;
47 
51 class Session : public std::enable_shared_from_this<ll::Session> {
52 
53 public:
59  static std::vector<ll::DeviceDescriptor> getAvailableDevices();
60 
66  static std::vector<vk::LayerProperties> getVulkanInstanceLayerProperties();
67 
73  static std::vector<vk::ExtensionProperties> getVulkanExtensionProperties();
74 
84  static std::shared_ptr<ll::Session> create();
85 
97  static std::shared_ptr<ll::Session> create(const ll::SessionDescriptor& descriptor);
98 
99  Session(const Session& session) = delete;
100  Session(Session&& session) = delete;
101 
103 
104  Session& operator=(const Session& session) = delete;
105  Session& operator=(Session&& session) = delete;
106 
117  std::shared_ptr<ll::Memory> getHostMemory() const noexcept;
118 
127  std::shared_ptr<ll::Memory> getDeviceMemory() const noexcept;
128 
134  // const std::unique_ptr<ll::Interpreter>& getInterpreter() const noexcept;
135 
141  vk::PhysicalDeviceMemoryProperties getPhysicalDeviceMemoryProperties() const;
142 
152 
158  const ll::DeviceDescriptor& getDeviceDescriptor() const noexcept;
159 
170  bool isImageDescriptorSupported(const ll::ImageDescriptor& descriptor) const noexcept;
171 
190  std::shared_ptr<ll::Memory> createMemory(const ll::MemoryPropertyFlags& flags, const uint64_t pageSize, bool exactFlagsMatch = false);
191 
197  std::unique_ptr<ll::CommandBuffer> createCommandBuffer() const;
198 
204  std::unique_ptr<ll::Duration> createDuration() const;
205 
217  std::shared_ptr<ll::Program> createProgram(const std::string& spirvPath) const;
218 
231  std::shared_ptr<ll::Program> createProgram(const std::vector<uint8_t>& spirv) const;
232 
241  void setProgram(const std::string& name, const std::shared_ptr<ll::Program>& program);
242 
252  std::shared_ptr<ll::Program> getProgram(const std::string& name) const;
253 
260 
268  std::shared_ptr<ll::ComputeNode> createComputeNode(const ll::ComputeNodeDescriptor& descriptor);
269 
279  std::shared_ptr<ll::ComputeNode> createComputeNode(const std::string& builderName);
280 
290  ll::ComputeNodeDescriptor createComputeNodeDescriptor(const std::string& builderName) const;
291 
292  std::shared_ptr<ll::ContainerNode> createContainerNode(const ll::ContainerNodeDescriptor& descriptor);
293 
294  std::shared_ptr<ll::ContainerNode> createContainerNode(const std::string& builderName);
295 
296  ll::ContainerNodeDescriptor createContainerNodeDescriptor(const std::string& builderName) const;
297 
306  void run(const ll::CommandBuffer& cmdBuffer);
307 
329  void run(const ll::ComputeNode& node);
330 
352  void run(const ll::ContainerNode& node);
353 
359  void script(const std::string& code);
360 
366  void scriptFile(const std::string& filename);
367 
377  void loadLibrary(const std::string& filename);
378 
384  ll::vec3ui getGoodComputeLocalShape(ll::ComputeDimension dimensions) const noexcept;
385 
393  std::string help(const std::string& builderName) const;
394 
402  bool hasReceivedVulkanWarningMessages() const noexcept;
403 
404 private:
405  static uint32_t findComputeFamilyQueueIndex(vk::PhysicalDevice& physicalDevice);
406 
407  // Session objects should be created through factory methods
408  Session(const ll::SessionDescriptor& descriptor);
409 
410  void initDescriptor();
411  void initDevice();
412 
413  const ll::SessionDescriptor m_descriptor;
414  ll::DeviceDescriptor m_deviceDescriptor;
415 
416  std::shared_ptr<ll::vulkan::Instance> m_instance;
417  std::shared_ptr<ll::vulkan::Device> m_device;
418 
419  std::shared_ptr<ll::Interpreter> m_interpreter;
420 
421  std::map<std::string, std::shared_ptr<ll::Program>> m_programRegistry;
422 
423  std::shared_ptr<ll::Memory> m_hostMemory;
424  std::shared_ptr<ll::Memory> m_deviceMemory;
425 };
426 
427 } // namespace ll
428 
429 #endif // LLUVIA_CORE_SESSION_H_
ImageDescriptor class and related enumerations.
MemoryPropertyFlags class.
NodeBuilderDescriptor class.
SessionDescriptor class.
Class for command buffer.
Definition: CommandBuffer.h:63
Class for describing a compute node node.
Definition: ComputeNodeDescriptor.h:33
Class representing compute nodes.
Definition: ComputeNode.h:38
Class for describing a container node.
Definition: ContainerNodeDescriptor.h:25
Definition: ContainerNode.h:24
Definition: Duration.h:22
Stores all relevant information for creating ll::Image objects.
Definition: ImageDescriptor.h:189
Definition: Interpreter.h:34
Class to manage allocation of objects into a specific type of memory.
Definition: Memory.h:92
Class representing Vulkan shader modules in SPIR-V representation.
Definition: Program.h:37
Definition: SessionDescriptor.h:16
Class that contains all the state required to run compute operations on a compute device.
Definition: Session.h:51
std::string help(const std::string &builderName) const
Returns the help string of a given node builder.
const ll::DeviceDescriptor & getDeviceDescriptor() const noexcept
Gets the device descriptor associated to this session.
std::shared_ptr< ll::Program > createProgram(const std::string &spirvPath) const
Creates a program object reading a file at a given path.
std::shared_ptr< ll::Memory > getHostMemory() const noexcept
Returns a pointer to ll::Memory object that is HOST_LOCAL and HOST_COHERENT.
ll::ContainerNodeDescriptor createContainerNodeDescriptor(const std::string &builderName) const
ll::ComputeNodeDescriptor createComputeNodeDescriptor(const std::string &builderName) const
Creates a compute node descriptor given its builder name.
vk::PhysicalDeviceMemoryProperties getPhysicalDeviceMemoryProperties() const
Gets the Lua interpreter.
std::shared_ptr< ll::Memory > getDeviceMemory() const noexcept
Returns a pointer to ll::Memory object that is DEVICE_LOCAL.
std::vector< ll::NodeBuilderDescriptor > getNodeBuilderDescriptors() const
Gets the node builder descriptors currently registered.
static std::vector< vk::LayerProperties > getVulkanInstanceLayerProperties()
Gets the Vulkan instance layer properties available to this machine.
Session & operator=(const Session &session)=delete
std::shared_ptr< ll::ComputeNode > createComputeNode(const ll::ComputeNodeDescriptor &descriptor)
Creates a compute node.
static std::vector< vk::ExtensionProperties > getVulkanExtensionProperties()
Gets the Vulkan extension properties available to this machine.
bool hasReceivedVulkanWarningMessages() const noexcept
Tells whether or not this session has triggered Vulkan warning messages.
std::shared_ptr< ll::ContainerNode > createContainerNode(const ll::ContainerNodeDescriptor &descriptor)
static std::shared_ptr< ll::Session > create()
Creates a new ll::Session object.
std::shared_ptr< ll::Program > getProgram(const std::string &name) const
Gets a program given its name in the registry.
ll::vec3ui getGoodComputeLocalShape(ll::ComputeDimension dimensions) const noexcept
Returns the suggested local grid shape for compute nodes given the number of dimensions.
std::vector< ll::MemoryPropertyFlags > getSupportedMemoryFlags() const
Gets the supported memory flags.
Session & operator=(Session &&session)=delete
std::shared_ptr< ll::Memory > createMemory(const ll::MemoryPropertyFlags &flags, const uint64_t pageSize, bool exactFlagsMatch=false)
Creates a memory.
bool isImageDescriptorSupported(const ll::ImageDescriptor &descriptor) const noexcept
Determines if parameters in image descriptor are supported for image creation.
Session(Session &&session)=delete
void loadLibrary(const std::string &filename)
Loads a library made of SPIR-V shader code and Lua scripts.
void setProgram(const std::string &name, const std::shared_ptr< ll::Program > &program)
Sets a program with a given name into the registry.
static std::shared_ptr< ll::Session > create(const ll::SessionDescriptor &descriptor)
Creates a new ll::Session object.
void run(const ll::CommandBuffer &cmdBuffer)
Runs a ll::CommandBuffer.
Session(const Session &session)=delete
void script(const std::string &code)
Runs Lua script code into the session's internal interpreter.
static std::vector< ll::DeviceDescriptor > getAvailableDevices()
Gets the available devices.
std::unique_ptr< ll::Duration > createDuration() const
Creates a Duration object.
std::unique_ptr< ll::CommandBuffer > createCommandBuffer() const
Creates a command buffer.
void scriptFile(const std::string &filename)
Runs a Lua script file into the the session's internal interpreter.
Definition: Buffer.h:28
ComputeDimension
Supported compute dimensions.
Definition: ComputeDimension.h:21
Definition: DeviceDescriptor.h:18
Describes the attributes of a node builder.
Definition: NodeBuilderDescriptor.h:20
Common types.