| 82 | */ |
| 83 | template<typename S = float, typename P = float> |
| 84 | void rebuild(const std::vector<std::shared_ptr<Tensor>>& tensors, |
| 85 | const std::vector<uint32_t>& spirv, |
| 86 | const Workgroup& workgroup = {}, |
| 87 | const std::vector<S>& specializationConstants = {}, |
| 88 | const std::vector<P>& pushConstants = {}) |
| 89 | { |
| 90 | KP_LOG_DEBUG("Kompute Algorithm rebuild started"); |
| 91 | |
| 92 | this->mTensors = tensors; |
| 93 | this->mSpirv = spirv; |
| 94 | |
| 95 | if (specializationConstants.size()) { |
| 96 | if (this->mSpecializationConstantsData) { |
| 97 | free(this->mSpecializationConstantsData); |
| 98 | } |
| 99 | uint32_t memorySize = |
| 100 | sizeof(decltype(specializationConstants.back())); |
| 101 | uint32_t size = specializationConstants.size(); |
| 102 | uint32_t totalSize = size * memorySize; |
| 103 | this->mSpecializationConstantsData = malloc(totalSize); |
| 104 | memcpy(this->mSpecializationConstantsData, |
| 105 | specializationConstants.data(), |
| 106 | totalSize); |
| 107 | this->mSpecializationConstantsDataTypeMemorySize = memorySize; |
| 108 | this->mSpecializationConstantsSize = size; |
| 109 | } |
| 110 | |
| 111 | if (pushConstants.size()) { |
| 112 | if (this->mPushConstantsData) { |
| 113 | free(this->mPushConstantsData); |
| 114 | } |
| 115 | uint32_t memorySize = sizeof(decltype(pushConstants.back())); |
| 116 | uint32_t size = pushConstants.size(); |
| 117 | uint32_t totalSize = size * memorySize; |
| 118 | this->mPushConstantsData = malloc(totalSize); |
| 119 | memcpy(this->mPushConstantsData, pushConstants.data(), totalSize); |
| 120 | this->mPushConstantsDataTypeMemorySize = memorySize; |
| 121 | this->mPushConstantsSize = size; |
| 122 | } |
| 123 | |
| 124 | this->setWorkgroup( |
| 125 | workgroup, this->mTensors.size() ? this->mTensors[0]->size() : 1); |
| 126 | |
| 127 | // Descriptor pool is created first so if available then destroy all |
| 128 | // before rebuild |
| 129 | if (this->isInit()) { |
| 130 | this->destroy(); |
| 131 | } |
| 132 | |
| 133 | this->createParameters(); |
| 134 | this->createShaderModule(); |
| 135 | this->createPipeline(); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Destructor for Algorithm which is responsible for freeing and desroying |
no test coverage detected