* 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_format.h
* \brief TLV on-disk format for the PyPTO kernel bundle (.pyptokb).
*/
#pragma once
#include <cstdint>
#include <cstdlib>
#include <string>
namespace npu::tile_fwk::bundle {
constexpr uint64_t kBundleMagic = 0x00424B4F54505950ULL;
constexpr uint32_t kBundleVersion = 1;
constexpr uint32_t kValueAlign = 4096;
enum class TlvType : uint32_t {
AicoreKernel = 1,
AicpuSo = 2,
DevProgram = 3,
CtrlFlowCache = 4,
SymbolMeta = 5,
};
struct BundleHeader {
uint64_t magic;
uint32_t version;
uint32_t flags;
uint32_t tlvCount;
uint32_t headerSize;
uint64_t totalSize;
uint8_t reserved[28];
uint32_t headerCrc32;
};
static_assert(sizeof(BundleHeader) == 64, "BundleHeader must be 64 bytes");
struct TlvHeader {
uint32_t type;
uint32_t flags;
uint64_t valueOffset;
uint64_t valueLength;
uint32_t valueCrc32;
uint32_t reserved;
};
static_assert(sizeof(TlvHeader) == 32, "TlvHeader must be 32 bytes");
inline bool IsKernelBundleEnabled()
{
static const bool enabled = []() {
const char* v = std::getenv("PYPTO_ENABLE_KERNEL_BUNDLE");
return v != nullptr && v[0] == '1' && v[1] == '\0';
}();
return enabled;
}
inline const std::string& KernelBundleOutPath()
{
static const std::string path = []() {
const char* p = std::getenv("PYPTO_KERNEL_BUNDLE_PATH");
return (p != nullptr && p[0] != '\0') ? std::string(p) : std::string("foo.pyptokb");
}();
return path;
}
}