MCPcopy Create free account
hub / github.com/KomputeProject/kompute / Algorithm

Class Algorithm

src/include/kompute/Algorithm.hpp:16–315  ·  view source on GitHub ↗

Abstraction for compute shaders that are run on top of tensors grouped via ParameterGroups (which group descriptorsets) */

Source from the content-addressed store, hash-verified

14 ParameterGroups (which group descriptorsets)
15*/
16class Algorithm
17{
18 public:
19 /**
20 * Main constructor for algorithm with configuration parameters to create
21 * the underlying resources.
22 *
23 * @param device The Vulkan device to use for creating resources
24 * @param tensors (optional) The tensors to use to create the descriptor
25 * resources
26 * @param spirv (optional) The spirv code to use to create the algorithm
27 * @param workgroup (optional) The kp::Workgroup to use for the dispatch
28 * which defaults to kp::Workgroup(tensor[0].size(), 1, 1) if not set.
29 * @param specializationConstants (optional) The templatable param is to be
30 * used to initialize the specialization constants which cannot be changed
31 * once set.
32 * @param pushConstants (optional) This templatable param is to be used
33 * when initializing the pipeline, which set the size of the push constants
34 * - these can be modified but all new values must have the same data type
35 * and length as otherwise it will result in errors.
36 */
37 template<typename S = float, typename P = float>
38 Algorithm(std::shared_ptr<vk::Device> device,
39 const std::vector<std::shared_ptr<Tensor>>& tensors = {},
40 const std::vector<uint32_t>& spirv = {},
41 const Workgroup& workgroup = {},
42 const std::vector<S>& specializationConstants = {},
43 const std::vector<P>& pushConstants = {})
44 {
45 KP_LOG_DEBUG("Kompute Algorithm Constructor with device");
46
47 this->mDevice = device;
48
49 if (tensors.size() && spirv.size()) {
50 KP_LOG_INFO(
51 "Kompute Algorithm initialising with tensor size: {} and "
52 "spirv size: {}",
53 tensors.size(),
54 spirv.size());
55 this->rebuild(tensors,
56 spirv,
57 workgroup,
58 specializationConstants,
59 pushConstants);
60 } else {
61 KP_LOG_INFO(
62 "Kompute Algorithm constructor with empty tensors and or "
63 "spirv so not rebuilding vulkan components");
64 }
65 }
66
67 /**
68 * Rebuild function to reconstruct algorithm with configuration parameters
69 * to create the underlying resources.
70 *
71 * @param tensors The tensors to use to create the descriptor resources
72 * @param spirv The spirv code to use to create the algorithm
73 * @param workgroup (optional) The kp::Workgroup to use for the dispatch

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected