* Copyright (c) 2025-2026 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
* \file kernel_bundle_loader.h
* \brief Loads a .pyptokb into memory and exposes its segments.
*/
#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include "machine/runtime/launcher/ctrl_flow_cache_manager.h"
#include "machine/utils/dynamic/dev_encode_program.h"
#include "machine/utils/dynamic/dev_encode_tensor.h"
namespace npu::tile_fwk::bundle {
struct LoadedBundle {
uint64_t bundleKey{0};
std::vector<uint8_t> aicoreKernel;
std::vector<uint8_t> aicpuSo;
std::vector<uint8_t> devProgram;
dynamic::CtrlFlowCacheBlob ctrlFlowCache;
std::vector<uint8_t> symbolMeta;
std::string displayName;
std::vector<dynamic::DevDynamicCellMatchStridePatch> cellMatchStridePatches;
const dynamic::DevAscendProgram* Head() const
{
return reinterpret_cast<const dynamic::DevAscendProgram*>(devProgram.data());
}
uint64_t GetWorkspaceSize() const { return Head()->memBudget.Total(); }
uint64_t GetHashKey() const { return Head()->hashKey; }
uint64_t GetConfigKey() const { return Head()->configKey; }
uint32_t GetArchInfo() const { return static_cast<uint32_t>(Head()->devArgs.archInfo); }
bool HasCtrlFlowCache() const { return !ctrlFlowCache.empty(); }
bool HasSymbolMeta() const { return !symbolMeta.empty(); }
};
class KernelBundleLoader {
public:
static std::shared_ptr<LoadedBundle> LoadFromFile(const std::string& path);
static std::shared_ptr<LoadedBundle> LoadFromMemory(const uint8_t* p, size_t n);
};
}