乐于分享
好东西不私藏

TensorRT-LLM 0.5.0 源码之二十九

TensorRT-LLM 0.5.0 源码之二十九

TensorDataType

typedef enum datatype_enum
{
    TYPE_INVALID,
    TYPE_BOOL,
    TYPE_UINT8,
    TYPE_UINT16,
    TYPE_UINT32,
    TYPE_UINT64,
    TYPE_INT8,
    TYPE_INT16,
    TYPE_INT32,
    TYPE_INT64,
    TYPE_FP16,
    TYPE_FP32,
    TYPE_FP64,
    TYPE_BYTES,
    TYPE_BF16,
    TYPE_FP8_E4M3,
    TYPE_STR,
    TYPE_VOID,
    TYPE_INT32_PTR,
} DataType;

template
 <typename T>
struct
 TensorDataType
{
};

template
 <>
struct
 TensorDataType<bool>
{
    static
 constexpr DataType value = TYPE_BOOL;
};

template
 <>
struct
 TensorDataType<std::uint8_t>
{
    static
 constexpr DataType value = TYPE_UINT8;
};

template
 <>
struct
 TensorDataType<std::uint16_t>
{
    static
 constexpr DataType value = TYPE_UINT16;
};

template
 <>
struct
 TensorDataType<std::uint32_t>
{
    static
 constexpr DataType value = TYPE_UINT32;
};

template
 <>
struct
 TensorDataType<std::uint64_t>
{
    static
 constexpr DataType value = TYPE_UINT64;
};

#if !defined(_WIN32)

template
 <>
struct
 TensorDataType<unsigned long long>
{
    static
 constexpr DataType value = TYPE_UINT64;
};
#endif // !defined(_WIN32)


static_assert
(sizeof(std::uint64_t) == sizeof(unsigned long long), "");

template
 <>
struct
 TensorDataType<std::int8_t>
{
    static
 constexpr DataType value = TYPE_INT8;
};

template
 <>
struct
 TensorDataType<std::int16_t>
{
    static
 constexpr DataType value = TYPE_INT16;
};

template
 <>
struct
 TensorDataType<std::int32_t>
{
    static
 constexpr DataType value = TYPE_INT32;
};

template
 <>
struct
 TensorDataType<std::int64_t>
{
    static
 constexpr DataType value = TYPE_INT64;
};

template
 <>
struct
 TensorDataType<half>
{
    static
 constexpr DataType value = TYPE_FP16;
};

template
 <>
struct
 TensorDataType<float>
{
    static
 constexpr DataType value = TYPE_FP32;
};

template
 <>
struct
 TensorDataType<double>
{
    static
 constexpr DataType value = TYPE_FP64;
};

template
 <>
struct
 TensorDataType<char>
{
    static
 constexpr DataType value = TYPE_BYTES;
};

#ifdef ENABLE_BF16

template
 <>
struct
 TensorDataType<__nv_bfloat16>
{
    static
 constexpr DataType value = TYPE_BF16;
};
#endif


#ifdef ENABLE_FP8

template
 <>
struct
 TensorDataType<__nv_fp8_e4m3>
{
    static
 constexpr DataType value = TYPE_FP8_E4M3;
};
#endif


template
 <>
struct
 TensorDataType<std::string>
{
    static
 constexpr DataType value = TYPE_STR;
};

template
 <>
struct
 TensorDataType<void>
{
    static
 constexpr DataType value = TYPE_VOID;
};

template
 <>
struct
 TensorDataType<int*>
{
    static
 constexpr DataType value = TYPE_INT32_PTR;
};

template
 <>
struct
 TensorDataType<const int*>
{
    static
 constexpr DataType value = TYPE_INT32_PTR;
};


template
 <typename T>
DataType getTensorType()
{
    return
 TensorDataType<typename std::remove_cv<T>::type>::value;
}

Tensor

typedef enum memorytype_enum
{
    MEMORY_CPU,
    MEMORY_CPU_PINNED,
    MEMORY_GPU
} MemoryType;
class Tensor
{
public
:
    // Do not write to these variables directly. Use copy / move constructors instead.

    MemoryType where;
    DataType type;
    std::vector<size_t> shape;
    void
 const* data; // TODO modify from const void* to void* const

    Tensor
();
    Tensor
(MemoryType _where, DataType _type, std::vector<size_t> const& _shape, void const* _data);

    std::size_t size() const
;
    std::size_t sizeBytes() const
;

    std::string whereToString() const
;
    std::string toString() const
;
    std::string getNumpyTypeDesc(DataType type) const
;

void saveNpy(const std::string& filename) const
;
static Tensor loadNpy(const std::string& npy_file, const MemoryType where)
;

static DataType typeFromNumpyDesc(std::string type)
;
static size_t getTypeSize(DataType type)
;

    template
 <typename T>
inline T getVal(size_t index) const
{
        TLLM_LOG_DEBUG
("%s start", __PRETTY_FUNCTION__);
        TLLM_CHECK
(where == MEMORY_CPU);
        TLLM_CHECK
(data != nullptr);
        TLLM_CHECK_WITH_INFO
(index < size(), "index is larger than buffer size");

        if
 (getTensorType<T>() != type)
        {
            TLLM_LOG_DEBUG
("getVal with type %s, but data type is: %s", getNumpyTypeDesc(getTensorType<T>()).c_str(),
                getNumpyTypeDesc
(type).c_str());
        }
        return
 ((T*) data)[index];
    }

    template
 <typename T>
inline T getVal() const
{
        TLLM_LOG_DEBUG
("%s start", __PRETTY_FUNCTION__);
        if
 (getTensorType<T>() != type)
        {
            TLLM_LOG_DEBUG
("getVal with type %s, but data type is: %s", getNumpyTypeDesc(getTensorType<T>()).c_str(),
                getNumpyTypeDesc
(type).c_str());
        }
        return
 getVal<T>(0);
    }

    template
 <typename T>
inline T* getPtr() const
{
        TLLM_LOG_DEBUG
("%s start", __PRETTY_FUNCTION__);
        if
 (getTensorType<T>() != type)
        {
            TLLM_LOG_DEBUG
("getPtr with type %s, but data type is: %s", getNumpyTypeDesc(getTensorType<T>()).c_str(),
                getNumpyTypeDesc
(type).c_str());
        }
        return
 (T*) data;
    }

inline void* getPtrWithOffset(size_t offset) const
{
        TLLM_LOG_DEBUG
("%s start", __PRETTY_FUNCTION__);
        if
 (data == nullptr)
        {
            return
 (void*) data;
        }
        else

        {
            TLLM_CHECK_WITH_INFO
(offset < size(), "offset is larger than buffer size");
            return
 (void*) ((char*) data + offset * Tensor::getTypeSize(type));
        }
    }

    template
 <typename T>
inline T* getPtrWithOffset(size_t offset) const
{
        TLLM_LOG_DEBUG
("%s start", __PRETTY_FUNCTION__);
        if
 (getTensorType<T>() != type)
        {
            TLLM_LOG_DEBUG
("getVal with type %s, but data type is: %s", getNumpyTypeDesc(getTensorType<T>()).c_str(),
                getNumpyTypeDesc
(type).c_str());
        }
        if
 (data == nullptr)
        {
            return
 (T*) data;
        }
        else

        {
            TLLM_CHECK_WITH_INFO
(
                offset < size(), fmtstr("offset (%lu) is larger than buffer size (%lu)", offset, size()));
            return
 ((T*) data) + offset;
        }
    }

    template
 <typename T>
    T max() const
{
        if
 (getTensorType<T>() != type)
        {
            TLLM_LOG_DEBUG
("getVal with type %s, but data type is: %s", getNumpyTypeDesc(getTensorType<T>()).c_str(),
                getNumpyTypeDesc
(type).c_str());
        }
        TLLM_CHECK_WITH_INFO
(shape.size() > 0 && data != nullptr, "Should be a non-empty tensor.");
        TLLM_CHECK_WITH_INFO
(where == MEMORY_CPU || where == MEMORY_CPU_PINNED,
            "max() supports MEMORY_CPU or MEMORY_CPU_PINNED tensor."
);
        size_t
 max_idx = 0;
        T max_val = getVal<T>(max_idx);
        for
 (size_t i = 1; i < size(); ++i)
        {
            T val = getVal<T>(i);
            if
 (val > max_val)
            {
                max_idx = i;
                max_val = val;
            }
        }
        return
 max_val;
    }

    template
 <typename T>
    T min() const
{
        if
 (getTensorType<T>() != type)
        {
            TLLM_LOG_DEBUG
("getVal with type %s, but data type is: %s", getNumpyTypeDesc(getTensorType<T>()).c_str(),
                getNumpyTypeDesc
(type).c_str());
        }
        TLLM_CHECK_WITH_INFO
(shape.size() > 0 && data != nullptr, "Should be a non-empty tensor.");
        TLLM_CHECK_WITH_INFO
(where == MEMORY_CPU || where == MEMORY_CPU_PINNED,
            "min() supports MEMORY_CPU or MEMORY_CPU_PINNED tensor."
);
        size_t
 min_idx = 0;
        T min_val = getVal<T>(min_idx);
        for
 (size_t i = 1; i < size(); ++i)
        {
            T val = getVal<T>(i);
            if
 (val < min_val)
            {
                min_idx = i;
                min_val = val;
            }
        }
        return
 min_val;
    }

    template
 <typename T>
    T any(T val) const
{
        if
 (getTensorType<T>() != type)
        {
            TLLM_LOG_DEBUG
("getVal with type %s, but data type is: %s", getNumpyTypeDesc(getTensorType<T>()).c_str(),
                getNumpyTypeDesc
(type).c_str());
        }
        TLLM_CHECK_WITH_INFO
(shape.size() > 0 && data != nullptr, "Should be a non-empty tensor.");
        TLLM_CHECK_WITH_INFO
(where == MEMORY_CPU || where == MEMORY_CPU_PINNED,
            "any() supports MEMORY_CPU or MEMORY_CPU_PINNED tensor."
);
        for
 (size_t i = 0; i < size(); ++i)
        {
            if
 (getVal<T>(i) == val)
            {
                return
 true;
            }
        }
        return
 false;
    }

    template
 <typename T>
    T all(T val) const
{
        if
 (getTensorType<T>() != type)
        {
            TLLM_LOG_DEBUG
("getVal with type %s, but data type is: %s", getNumpyTypeDesc(getTensorType<T>()).c_str(),
                getNumpyTypeDesc
(type).c_str());
        }
        TLLM_CHECK_WITH_INFO
(shape.size() > 0 && data != nullptr, "Should be a non-empty tensor.");
        TLLM_CHECK_WITH_INFO
(where == MEMORY_CPU || where == MEMORY_CPU_PINNED,
            "all() supports MEMORY_CPU or MEMORY_CPU_PINNED tensor."
);
        for
 (size_t i = 0; i < size(); ++i)
        {
            if
 (getVal<T>(i) != val)
            {
                return
 false;
            }
        }
        return
 true;
    }

void updateShape(size_t idx, size_t val)
{
        // TODO: find a better way to update the shape

        std::vector<size_t>& shape_ref = const_cast<std::vector<size_t>&>(shape);
        shape_ref[idx] = val;
    }

inline bool isValid() const
{
        return
 size() > 0 && data != nullptr;
    }

    Tensor slice(std::vector<size_t> shape, size_t offset = 0) const
;

private
:
static void parseNpyIntro(FILE*& f_ptr, uint32_t& header_len, uint32_t& start_data)
;
static int parseNpyHeader(FILE*& f_ptr, uint32_t header_len, DataType& type, std::vector<size_t>& shape)
;
};
Tensor::Tensor()
    : // a none tensor.
    where
(MEMORY_CPU)
    , type(TYPE_INVALID)
    , shape({})
    , data(nullptr)
{
}


Tensor::Tensor(MemoryType _where, DataType _type, std::vector<size_t> const& _shape, void const* _data)
    : where(_where)
    , type(_type)
    , shape(_shape)
    , data(_data)
{
}
void Tensor::parseNpyIntro(FILE*& f_ptr, uint32_t& header_len, uint32_t& start_data)
{
    const
 char magic[]
        = "\x93"
          "NUMPY"
;
    char
 magic_test[sizeof(magic)] = "\0";

    size_t
 n_elems = fread((void*) magic_test, sizeof(char), sizeof(magic) - 1, f_ptr);
    if
 (n_elems != sizeof(magic) - 1 || std::string(magic) != std::string(magic_test))
    {
        throw
 std::runtime_error("Could read magic token in NPY file");
    }

    uint8_t
 npy_major = 0;
    uint8_t
 npy_minor = 0;
    n_elems = fread((void*) &npy_major, sizeof(uint8_t), 1, f_ptr);
    n_elems += fread((void*) &npy_minor, sizeof(uint8_t), 1, f_ptr);

    if
 (npy_major == 1)
    {
        uint16_t
 header_len_u16 = 0;
        n_elems = fread((void*) &header_len_u16, sizeof(uint16_t), 1, f_ptr);
        header_len = header_len_u16;
    }
    else
 if (npy_major == 2)
    {
        uint32_t
 header_len_u32 = 0;
        n_elems = fread((void*) &header_len_u32, sizeof(uint32_t), 1, f_ptr);
        header_len = header_len_u32;
    }
    else

    {
        throw
 std::runtime_error("Unsupported npy version: " + std::to_string(npy_major));
    }

    start_data = 8 + 2 * npy_major + header_len;
}
int Tensor::parseNpyHeader(FILE*& f_ptr, uint32_t header_len, DataType& type, std::vector<size_t>& shape)
{
    char
* header_c = (char*) malloc(header_len * sizeof(char));
    size_t
 n_elems = fread((void*) header_c, sizeof(char), header_len, f_ptr);
    if
 (n_elems != header_len)
    {
        free
(header_c);
        return
 -1;
    }
    std::string header(header_c, header_len)
;
    free
(header_c);

    size_t
 start, end;
    start = header.find("'descr'") + 7;
    start = header.find("'", start);
    end = header.find("'", start + 1);
    type = typeFromNumpyDesc(header.substr(start + 2, end - start - 2));

    start = header.find("'fortran_order'") + 15;
    start = header.find(":", start);
    end = header.find(",", start + 1);
    if
 (header.substr(start + 1, end - start - 1).find("False") == std::string::npos)
    {
        throw
 std::runtime_error("Unsupported value for fortran_order while reading npy file");
    }

    start = header.find("'shape'") + 7;
    start = header.find("(", start);
    end = header.find(")", start + 1);

    std::istringstream shape_stream(header.substr(start + 1, end - start - 1))
;
    std::string token;

    shape.clear();
    while
 (std::getline(shape_stream, token, ','))
    {
        if
 (token.find_first_not_of(' ') == std::string::npos)
        {
            break
;
        }
        shape.push_back(std::stoul(token));
    }

    return
 0;
}
Tensor Tensor::loadNpy(const std::string& npy_file, const MemoryType where)
{
    DataType type;
    std::vector<size_t> shape;

    FILE* f_ptr = fopen(npy_file.c_str(), "rb");
    if
 (f_ptr == nullptr)
    {
        throw
 std::runtime_error("Could not open file " + npy_file);
    }
    uint32_t
 header_len, start_data;
    parseNpyIntro
(f_ptr, header_len, start_data);
    parseNpyHeader
(f_ptr, header_len, type, shape);

    const
 size_t size = std::accumulate(shape.begin(), shape.end(), size_t{1}, std::multiplies<size_t>());
    void
* data_cpu = malloc(size * Tensor::getTypeSize(type));
    void
* data = data_cpu;

    size_t
 n_elems = fread(data_cpu, Tensor::getTypeSize(type), size, f_ptr);
    TLLM_CHECK_WITH_INFO
(n_elems == size, "reading tensor failed");
    if
 (where == MEMORY_GPU)
    {
        cudaMalloc
(&data, size * Tensor::getTypeSize(type));
        cudaMemcpy
(data, data_cpu, size * Tensor::getTypeSize(type), cudaMemcpyHostToDevice);
        free
(data_cpu);
    }

    fclose
(f_ptr);
    return
 Tensor(where, type, shape, data);
}
size_t Tensor::size() const
{
    if
 (data == nullptr || shape.size() == 0)
    {
        return
 0;
    }
    return
 std::accumulate(shape.begin(), shape.end(), (size_t) 1, std::multiplies<size_t>());
}



size_t Tensor::sizeBytes() const
{
    return
 size() * Tensor::getTypeSize(type);
}


std::string Tensor::whereToString() const
{
    static
 const std::unordered_map<MemoryType, std::string> mem_to_string{
        {MEMORY_CPU, "CPU"}, {MEMORY_CPU_PINNED, "CPU_PINNED"}, {MEMORY_GPU, "GPU"}};
    return
 mem_to_string.at(where);
}


std::string Tensor::toString() const
{
    std::string memtype_str = whereToString();

    static
 const std::unordered_map<DataType, std::string> type_to_string{
        {TYPE_BOOL, "BOOL"},
        {TYPE_UINT8, "UINT8"},
        {TYPE_UINT16, "UINT16"},
        {TYPE_UINT32, "UINT32"},
        {TYPE_UINT64, "UINT64"},
        {TYPE_INT8, "INT8"},
        {TYPE_INT16, "INT16"},
        {TYPE_INT32, "INT32"},
        {TYPE_INT64, "INT64"},
        {TYPE_BF16, "BF16"},
        {TYPE_FP16, "FP16"},
        {TYPE_FP32, "FP32"},
        {TYPE_FP64, "FP64"},
        {TYPE_BYTES, "BYTES"},
        {TYPE_INVALID, "INVALID"},
        {TYPE_FP8_E4M3, "E4M3"},
        {TYPE_VOID, "VOID"},
    };
    return
 fmtstr("Tensor[where=%s, type=%s, shape=%s, data=%p]", memtype_str.c_str(), type_to_string.at(type).c_str(),
        vec2str
(shape).c_str(), data);
}

DataType Tensor::typeFromNumpyDesc(std::string type)
{
    static
 const std::unordered_map<std::string, DataType> type_map{{"?", TYPE_BOOL}, {"b", TYPE_BYTES},
        {"u1", TYPE_UINT8}, {"u2", TYPE_UINT16}, {"u4", TYPE_UINT32}, {"u8", TYPE_UINT64}, {"i1", TYPE_INT8},
        {"i2", TYPE_INT16}, {"i4", TYPE_INT32}, {"i8", TYPE_INT64}, {"f2", TYPE_FP16}, {"f4", TYPE_FP32},
        {"f8", TYPE_FP64}};
    TLLM_CHECK_WITH_INFO
(type_map.count(type) > 0, "numpy data type '" + type + "' not supported");
    return
 type_map.at(type);
}


size_t Tensor::getTypeSize(DataType type)
{
    static
 const std::unordered_map<DataType, size_t> type_map{{TYPE_BOOL, sizeof(bool)}, {TYPE_BYTES, sizeof(char)},
        {TYPE_UINT8, sizeof(uint8_t)}, {TYPE_UINT16, sizeof(uint16_t)}, {TYPE_UINT32, sizeof(uint32_t)},
        {TYPE_UINT64, sizeof(uint64_t)}, {TYPE_INT8, sizeof(int8_t)}, {TYPE_INT16, sizeof(int16_t)},
        {TYPE_INT32, sizeof(int32_t)}, {TYPE_INT64, sizeof(int64_t)},
#ifdef ENABLE_BF16

        {TYPE_BF16, sizeof(__nv_bfloat16)},
#endif

#ifdef ENABLE_FP8

        {TYPE_FP8_E4M3, sizeof(__nv_fp8_e4m3)},
#endif

        {TYPE_FP16, sizeof(half)}, {TYPE_FP32, sizeof(float)}, {TYPE_FP64, sizeof(double)}};
    return
 type_map.at(type);
}


std::string Tensor::getNumpyTypeDesc(DataType type) const
{
    static
 const std::unordered_map<DataType, std::string> type_map{{TYPE_INVALID, "x"}, {TYPE_BOOL, "?"},
        {TYPE_BYTES, "b"}, {TYPE_UINT8, "u1"}, {TYPE_UINT16, "u2"}, {TYPE_UINT32, "u4"}, {TYPE_UINT64, "u8"},
        {TYPE_INT8, "i1"}, {TYPE_INT16, "i2"}, {TYPE_INT32, "i4"}, {TYPE_INT64, "i8"}, {TYPE_FP16, "f2"},
        {TYPE_FP32, "f4"}, {TYPE_FP64, "f8"}};

    if
 (type == TYPE_BF16)
    {
        TLLM_LOG_WARNING
(
            "getNumpyTypeDesc(TYPE_BF16) returns an invalid type 'x' since Numpy doesn't "

            "support bfloat16 as of now, it will be properly extended if numpy supports. "

            "Please refer for the discussions https://github.com/numpy/numpy/issues/19808."
);
    }

    return
 type_map.count(type) > 0 ? type_map.at(type) : "x";
}
void Tensor::saveNpy(const std::string& filename) const
{
    // Save tensor to NPY 1.0 format (see https://numpy.org/neps/nep-0001-npy-format.html)

    void
* cpu_data = (void*) data;
    bool
 is_data_temp = false;
    size_t
 tensor_size = size();

#ifdef ENABLE_BF16

    if
 (type == TYPE_BF16)
    {
        TLLM_CHECK
(where == MemoryType::MEMORY_GPU);
        float
* data_fp32 = nullptr;
        cudaMalloc
(&data_fp32, tensor_size * sizeof(float));
        invokeCudaD2DcpyConvert
(data_fp32, static_cast<const __nv_bfloat16*>(data), tensor_size);
        Tensor{where, TYPE_FP32, shape, data_fp32}.saveNpy(filename);
        cudaFree
(data_fp32);
        return
;
    }
#endif


    if
 (where == MemoryType::MEMORY_GPU)
    {
        cpu_data = malloc(tensor_size * Tensor::getTypeSize(type));
        is_data_temp = true;
        cudaDeviceSynchronize
();
        cudaMemcpy
(cpu_data, data, tensor_size * Tensor::getTypeSize(type), cudaMemcpyDeviceToHost);
    }

    const
 char magic[]
        = "\x93"
          "NUMPY"
;
    const
 uint8_t npy_major = 1;
    const
 uint8_t npy_minor = 0;

    std::stringstream header_stream;
    header_stream << "{'descr': '" << getNumpyTypeDesc(type) << "', 'fortran_order': False, 'shape': (";
    for
 (size_t i = 0; i < shape.size(); ++i)
    {
        header_stream << shape[i];
        if
 (i + 1 < shape.size() || shape.size() == 1)
        {
            header_stream << ", ";
        }
    }
    header_stream << ")}";
    int
 base_length = 6 + 4 + header_stream.str().size();
    int
 pad_length = 16 * ((base_length + 1 + 15) / 16); // Take ceiling of base_length + 1 (for '\n' ending)
    for
 (int i = 0; i < pad_length - base_length; ++i)
    {
        header_stream << ((i == pad_length - base_length - 1) ? "\n" : "\x20");
    }
    std::string header = header_stream.str();
    const
 uint16_t header_len = header.size();

    FILE* f_ptr = fopen(filename.c_str(), "wb");
    TLLM_CHECK_WITH_INFO
(f_ptr != nullptr, fmtstr("Unable to open %s for writing.\n", filename.c_str()));

    fwrite
(magic, sizeof(char), sizeof(magic) - 1, f_ptr);
    fwrite
(&npy_major, sizeof(uint8_t), 1, f_ptr);
    fwrite
(&npy_minor, sizeof(uint8_t), 1, f_ptr);
    fwrite
(&header_len, sizeof(uint16_t), 1, f_ptr);
    fwrite
(header.c_str(), sizeof(char), header_len, f_ptr);
    fwrite
(cpu_data, Tensor::getTypeSize(type), tensor_size, f_ptr);

    fclose
(f_ptr);

    if
 (is_data_temp)
    {
        free
(cpu_data);
    }
}
Tensor Tensor::slice(std::vector<size_t> shape, size_t offset) const
{
    if
 (this->data != nullptr)
    {
        size_t
 n_elts = this->size();
        size_t
 n_sliced_elts = std::accumulate(shape.begin(), shape.end(), size_t{1}, std::multiplies<size_t>());
        TLLM_CHECK_WITH_INFO
(n_sliced_elts + offset <= n_elts,
            fmtstr
("The number (%ld) of elements of sliced tensor exceeds that (%ld) of the original tensor",
                n_sliced_elts + offset, n_elts));
    }
    return
 Tensor(this->where, this->type, shape, this->getPtrWithOffset(offset));
}

TensorMap

class TensorMap
{
private
:
    std::unordered_map<std::string, Tensor> tensor_map_;

public
:
    TensorMap
() = default;
    TensorMap
(const std::unordered_map<std::string, Tensor>& tensor_map);
    TensorMap
(const std::vector<Tensor>& tensor_map);
    TensorMap
(std::initializer_list<std::pair<std::string, Tensor>> tensor_map);
    ~TensorMap();

inline size_t size() const
{
        return
 tensor_map_.size();
    }

inline bool contains(const std::string& key) const
{
        TLLM_LOG_DEBUG
("%s for key: %s", __PRETTY_FUNCTION__, key.c_str());
        return
 tensor_map_.find(key) != tensor_map_.end();
    }

    std::vector<std::string> keys() const
;

inline void insert(const std::string& key, const Tensor& value)
{
        TLLM_CHECK_WITH_INFO
(!contains(key), fmtstr("Duplicated key %s", key.c_str()));
        TLLM_CHECK_WITH_INFO
(
            value.isValid(), fmtstr("A none tensor or nullptr is not allowed (key is %s)", key.c_str()));
        tensor_map_.insert({key, value});
    }

inline void insertIfValid(const std::string& key, const Tensor& value)
{
        if
 (value.isValid())
        {
            insert
({key, value});
        }
    }

inline void insert(std::pair<std::string, Tensor> p)
{
        tensor_map_.insert(p);
    }

    // prevent converting int or size_t to string automatically

    Tensor at(int tmp)
= delete;
    Tensor at(size_t tmp)
= delete;

inline Tensor& at(const std::string& key)
{
        TLLM_LOG_DEBUG
("%s for key %s", __PRETTY_FUNCTION__, key.c_str());
        TLLM_CHECK_WITH_INFO
(contains(key),
            fmtstr
(
                "Cannot find a tensor of name %s in the tensor map (keys: %s)"
, key.c_str(), vec2str(keys()).c_str()));
        return
 tensor_map_.at(key);
    }

inline Tensor at(const std::string& key) const
{
        TLLM_CHECK_WITH_INFO
(contains(key),
            fmtstr
(
                "Cannot find a tensor of name %s in the tensor map (keys: %s)"
, key.c_str(), vec2str(keys()).c_str()));
        return
 tensor_map_.at(key);
    }

inline std::optional<Tensor> atOpt(const std::string& key) const
{
        if
 (contains(key))
            return
 tensor_map_.at(key);
        else

            return
 std::nullopt;
    }

inline Tensor& at(const std::string& key, Tensor& default_tensor)
{
        TLLM_LOG_DEBUG
("%s for key %s", __PRETTY_FUNCTION__, key.c_str());
        if
 (contains(key))
        {
            return
 tensor_map_.at(key);
        }
        return
 default_tensor;
    }

inline Tensor at(const std::string& key, Tensor& default_tensor) const
{
        TLLM_LOG_DEBUG
("%s for key %s", __PRETTY_FUNCTION__, key.c_str());
        if
 (contains(key))
        {
            return
 tensor_map_.at(key);
        }
        return
 default_tensor;
    }

inline Tensor& at(const std::string& key, Tensor&& default_tensor)
{
        TLLM_LOG_DEBUG
("%s for key %s", __PRETTY_FUNCTION__, key.c_str());
        if
 (contains(key))
        {
            return
 tensor_map_.at(key);
        }
        return
 default_tensor;
    }

inline Tensor at(const std::string& key, Tensor&& default_tensor) const
{
        if
 (contains(key))
        {
            return
 tensor_map_.at(key);
        }
        return
 default_tensor;
    }

    template
 <typename T>
inline T getVal(const std::string& key) const
{
        TLLM_CHECK_WITH_INFO
(contains(key),
            fmtstr
(
                "Cannot find a tensor of name %s in the tensor map (keys: %s)"
, key.c_str(), vec2str(keys()).c_str()));
        return
 tensor_map_.at(key).getVal<T>();
    }

    template
 <typename T>
inline std::optional<T> getValOpt(const std::string& key) const
{
        if
 (contains(key))
        {
            return
 tensor_map_.at(key).getVal<T>();
        }
        else

        {
            return
 std::nullopt;
        }
    }

    template
 <typename T>
inline T getVal(const std::string& key, T default_value) const
{
        if
 (contains(key))
        {
            return
 tensor_map_.at(key).getVal<T>();
        }
        return
 default_value;
    }

    template
 <typename T>
inline T getValWithOffset(const std::string& key, size_t index) const
{
        TLLM_CHECK_WITH_INFO
(contains(key),
            fmtstr
(
                "Cannot find a tensor of name %s in the tensor map (keys: %s)"
, key.c_str(), vec2str(keys()).c_str()));
        return
 tensor_map_.at(key).getVal<T>(index);
    }

    template
 <typename T>
inline T getValWithOffset(const std::string& key, size_t index, T default_value) const
{
        if
 (contains(key))
        {
            return
 tensor_map_.at(key).getVal<T>(index);
        }
        return
 default_value;
    }

    template
 <typename T>
inline T* getPtr(const std::string& key) const
{
        TLLM_CHECK_WITH_INFO
(contains(key),
            fmtstr
(
                "Cannot find a tensor of name %s in the tensor map (keys: %s)"
, key.c_str(), vec2str(keys()).c_str()));
        return
 tensor_map_.at(key).getPtr<T>();
    }

    template
 <typename T>
inline T* getPtr(const std::string& key, T* default_ptr) const
{
        if
 (contains(key))
        {
            return
 tensor_map_.at(key).getPtr<T>();
        }
        return
 default_ptr;
    }

    template
 <typename T>
inline T* getPtrWithOffset(const std::string& key, size_t index) const
{
        TLLM_CHECK_WITH_INFO
(contains(key),
            fmtstr
(
                "Cannot find a tensor of name %s in the tensor map (keys: %s)"
, key.c_str(), vec2str(keys()).c_str()));
        return
 tensor_map_.at(key).getPtrWithOffset<T>(index);
    }

    template
 <typename T>
inline T* getPtrWithOffset(const std::string& key, size_t index, T* default_ptr) const
{
        if
 (contains(key))
        {
            return
 tensor_map_.at(key).getPtrWithOffset<T>(index);
        }
        return
 default_ptr;
    }

inline std::unordered_map<std::string, Tensor> getMap() const
{
        return
 tensor_map_;
    }

    inline
 std::unordered_map<std::string, Tensor>::iterator begin()
{
        return
 tensor_map_.begin();
    }

    inline
 std::unordered_map<std::string, Tensor>::iterator end()
{
        return
 tensor_map_.end();
    }

    std::string toString()
;
static TensorMap fromNpyFolder(const std::string& base_folder)
;
void saveNpy(const std::string& base_folder)
;
};
TensorMap::TensorMap(const std::unordered_map<std::string, Tensor>& tensor_map)
{
    for
 (auto& kv : tensor_map)
    {
        if
 (kv.second.isValid())
        {
            insert
(kv.first, kv.second);
        }
        else

        {
            TLLM_LOG_DEBUG
(fmtstr("%s is not a valid tensor, skipping insert into TensorMap", kv.first.c_str()));
        }
    }
}
TensorMap::TensorMap(const std::vector<Tensor>& tensor_map)
{
    for
 (size_t i = 0; i < tensor_map.size(); i++)
    {
        insert
(std::to_string(i), tensor_map[i]);
    }
}
TensorMap::TensorMap(std::initializer_list<std::pair<std::string, Tensor>> tensor_map)
{
    for
 (auto& pair : tensor_map)
    {
        if
 (pair.second.isValid())
        {
            insert
(pair.first, pair.second);
        }
        else

        {
            TLLM_LOG_DEBUG
(fmtstr("%s is not a valid tensor, skipping insert into TensorMap", pair.first.c_str()));
        }
    }
}

TensorMap::~TensorMap()
{
    tensor_map_.clear();
}
std::vector<std::string> TensorMap::keys() const
{
    std::vector<std::string> key_names;
    for
 (auto& kv : tensor_map_)
    {
        key_names.push_back(kv.first);
    }
    return
 key_names;
}

std::string TensorMap::toString()
{
    std::stringstream ss;
    ss << "{";
    std::vector<std::string> key_names = keys();
    for
 (size_t i = 0; i < tensor_map_.size(); ++i)
    {
        ss << key_names[i] << ": " << at(key_names[i]).toString();
        if
 (i < tensor_map_.size() - 1)
        {
            ss << ", ";
        }
    }
    ss << "}";
    return
 ss.str();
}
TensorMap TensorMap::fromNpyFolder(const std::string& base_folder)
{
#if !defined(_WIN32)

    DIR* dir_p = opendir(base_folder.c_str());
    TLLM_CHECK_WITH_INFO
(dir_p != nullptr, fmtstr("Could not open folder %s. ", base_folder.c_str()));
    struct
 dirent* dp;

    TensorMap ret_tensor;
    while
 ((dp = readdir(dir_p)) != nullptr)
    {
        std::string filename(dp->d_name)
;
        size_t
 len = filename.length();
        if
 (len < 4 || filename.compare(len - 4, 4, ".npy"))
        {
            continue
;
        }

        size_t
 pos = filename.find('-');
        TLLM_CHECK_WITH_INFO
(pos != std::string::npos, fmtstr("Invalid filename: %s\n", filename.c_str()));

        MemoryType where;
        if
 (filename.compare(0, pos, "GPU") == 0)
        {
            where = MEMORY_GPU;
        }
        else
 if (filename.compare(0, pos, "CPU") == 0)
        {
            where = MEMORY_CPU;
        }
        else
 if (filename.compare(0, pos, "CPU_PINNED") == 0)
        {
            where = MEMORY_CPU_PINNED;
        }
        else

        {
            TLLM_CHECK_WITH_INFO
(false, fmtstr("Invalid filename: %s\n", filename.c_str()));
        }
        std::string key = filename.substr(pos + 1, len - pos - 5);

        ret_tensor.tensor_map_.insert({key, Tensor::loadNpy(base_folder + "/" + filename, where)});
    }

    closedir
(dir_p);

    return
 ret_tensor;
#else

    throw
 std::runtime_error("TensorMap::fromNpyFolder is not implemented on Windows.");
    return
 {};
#endif // !defined(_WIN32)

}
void TensorMap::saveNpy(const std::string& base_folder)
{
#if !defined(_WIN32)

    mode_t
 mode_0755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
    int
 ret = mkdir(base_folder.c_str(), mode_0755);
    TLLM_CHECK_WITH_INFO
(ret == 0 || errno == EEXIST, fmtstr("Could not create folder %s.\n", base_folder.c_str()));

    for
 (const auto& item : tensor_map_)
    {
        item.second.saveNpy(base_folder + "/" + item.second.whereToString() + "-" + item.first + ".npy");
    }
#else

    throw
 std::runtime_error("TensorMap::saveNpy is not implemented on Windows.");
#endif // !defined(_WIN32)

}

tensorConversion

inline DataType toTllmDataType(nvinfer1::DataType type)
{
    switch
 (type)
    {
    case
 nvinfer1::DataType::kFLOAT: return DataType::TYPE_FP32;
    case
 nvinfer1::DataType::kHALF: return DataType::TYPE_FP16;
    case
 nvinfer1::DataType::kBF16: return DataType::TYPE_BF16;
    case
 nvinfer1::DataType::kFP8: return DataType::TYPE_FP8_E4M3;
    case
 nvinfer1::DataType::kINT8: return DataType::TYPE_INT8;
    case
 nvinfer1::DataType::kUINT8: return DataType::TYPE_UINT8;
    case
 nvinfer1::DataType::kINT32: return DataType::TYPE_INT32;
    case
 nvinfer1::DataType::kINT64: return DataType::TYPE_INT64;
    case
 nvinfer1::DataType::kBOOL: return DataType::TYPE_BOOL;
    default
: TLLM_THROW("Unsupported data type: %d", static_cast<int>(type));
    }
}
inline MemoryType toTllmMemoryType(runtime::MemoryType type)
{
    switch
 (type)
    {
    case
 runtime::MemoryType::kGPU: return MemoryType::MEMORY_GPU;
    case
 runtime::MemoryType::kCPU: return MemoryType::MEMORY_CPU;
    case
 runtime::MemoryType::kPINNED: return MemoryType::MEMORY_CPU_PINNED;
    default
: TLLM_THROW("Unsupported memory type: %d", static_cast<int>(type));
    }
}
inline Tensor toTllmTensor(runtime::ITensor const& tensor)
{
    MemoryType memoryType = toTllmMemoryType(tensor.getMemoryType());
    DataType dataType = toTllmDataType(tensor.getDataType());

    auto
 const& dims = tensor.getShape();
    std::vector<std::size_t> shape(dims.d, dims.d + dims.nbDims)
;

    auto
* data = tensor.data();

    return
 Tensor(memoryType, dataType, shape, data);
}
inline Tensor toTllmTensor(runtime::IBuffer const& buffer)
{
    MemoryType memoryType = toTllmMemoryType(buffer.getMemoryType());
    DataType dataType = toTllmDataType(buffer.getDataType());
    std::vector<std::size_t> shape{buffer.getSize()};
    auto
* data = buffer.data();

    return
 Tensor(memoryType, dataType, shape, data);
}
template <typename T>
Tensor toTllmTensor(MemoryType memoryType, std::vector<std::size_t> const& shape, T* data)
{
    return
 Tensor{memoryType, getTensorType<T>(), shape, data};
}
template <typename T>
Tensor toTllmTensor(std::vector<T> const& data)
{
    return
 Tensor{MemoryType::MEMORY_CPU, getTensorType<T>(), {data.size()}, data.data()};
}
template <typename T>
Tensor scalarToTllmTensor(T& data)
{
    return
 Tensor{MemoryType::MEMORY_CPU, getTensorType<T>(), {1}, &data};
}

参考文献

  • • https://github.com/NVIDIA/TensorRT-LLM/blob/release/0.5.0/cpp/tensorrt_llm/common/tensor.h
点个「赞」+「在看」❤️
让我们知道这份文字有温暖到你,也是我们持续创作的最大动力!
推荐
TensorRT-LLM 0.5.0 源码之二十八
信息差的消失
Agent 数据生产与训练
基准测试设计:选择开放模型测试与封闭模型测试
gRPC 使用建议
flashinfer.sampling 实现四
AI 时代的组织变更
TensorRT-LLM 0.5.0 源码之二十七
flashinfer.sampling 实现三
什么是循环工程?AI 编码智能体的新范式
Trae IDE 实战指南:核心AI功能、Skill运用与项目开发全流程
Small matrix multiplication - Triton
从空文件夹到生成图表:Claude Code 实战教程
Claude Code 入门:研究者配置指南
Claude Code 究竟擅长什么?一次实测验证
GLM-5.2:面向长时序任务打造
Anthropic Fable 5
循环工程(Loop Engineering)
Agent SFT 标准数据格式 + Loss Mask 完整实现
4D Parallelism
TileLang与OpenAI Triton的核心区别
TensorRT-LLM 0.5.0 源码之二十六
Agent SFT 数据
Claude Code 的上限,就是你的上限
如何用Claude Code提升软件工程工作效率、改善生活
LLM推理优化的核心技术:深入理解KV缓存与分页注意力机制
MiMo-V2-Flash技术报告
AI原生开发中的MCP与CLI对比
Qwen3-TTS 技术报告
PagedAttention
如何让AI听懂你的“话外音”?GOAT-SLM模型实现更懂情感的语言交互
FlashAttention与PagedAttention详解:拯救GPU显存,让大模型飞起来的核心技术
LM-as-a-judge:LLM评估指南
LLM Sequence Packing
深入了解SmoothQuant:大模型高效量化背后的数学原理
语音合成(TTS)分句生成拼接时的响度一致性问题:现状、成因与对策
当扩散模型遇上流匹配:原来是一回事儿
语音合成中的“一对多”问题主流模型解决方案分析
使用LoRA对LLM进行微调的实用技巧
语音合成(TTS)中文自然度:问题、成因、解决方案
语音合成(TTS)跳跃与重复问题的解析:成因、机制及解决方案
最新!SpeechLLM 综述:架构、能力、挑战与未来全揭秘
基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-23 11:42:44 HTTP/1.1 GET : https://www.yeyulingfeng.com/a/867918.html
  2. 运行时间 : 0.197774s [ 吞吐率:5.06req/s ] 内存消耗:4,970.33kb 文件加载:145
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=bfa92288d971abbb651149d0aee7d2fc
  1. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_static.php ( 6.05 KB )
  7. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/ralouphie/getallheaders/src/getallheaders.php ( 1.60 KB )
  10. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  11. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  12. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  13. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  14. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  15. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  16. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  17. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  18. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  19. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions_include.php ( 0.16 KB )
  21. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions.php ( 5.54 KB )
  22. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  23. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  24. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  25. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/provider.php ( 0.19 KB )
  26. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  27. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  28. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  29. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/common.php ( 0.03 KB )
  30. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  32. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/alipay.php ( 3.59 KB )
  33. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  34. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/app.php ( 0.95 KB )
  35. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cache.php ( 0.78 KB )
  36. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/console.php ( 0.23 KB )
  37. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cookie.php ( 0.56 KB )
  38. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/database.php ( 2.48 KB )
  39. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/filesystem.php ( 0.61 KB )
  40. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/lang.php ( 0.91 KB )
  41. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/log.php ( 1.35 KB )
  42. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/middleware.php ( 0.19 KB )
  43. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/route.php ( 1.89 KB )
  44. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/session.php ( 0.57 KB )
  45. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/trace.php ( 0.34 KB )
  46. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/view.php ( 0.82 KB )
  47. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/event.php ( 0.25 KB )
  48. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  49. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/service.php ( 0.13 KB )
  50. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/AppService.php ( 0.26 KB )
  51. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  52. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  53. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  54. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  55. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  56. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/services.php ( 0.14 KB )
  57. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  58. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  59. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  60. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  61. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  62. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  63. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  64. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  65. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  66. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  67. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  68. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  69. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  70. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  71. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  72. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  73. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  74. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  75. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  76. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  77. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  78. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  79. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  80. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  81. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  82. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  83. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  84. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  85. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  86. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  87. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/Request.php ( 0.09 KB )
  88. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  89. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/middleware.php ( 0.25 KB )
  90. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  91. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  92. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  93. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  94. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  95. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  96. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  97. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  98. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  99. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  100. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  101. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  102. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  103. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/route/app.php ( 3.94 KB )
  104. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  105. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  106. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Index.php ( 9.87 KB )
  108. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/BaseController.php ( 2.05 KB )
  109. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  110. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  111. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  112. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  113. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  114. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  115. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  116. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  117. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  118. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  119. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  120. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  121. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  122. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  123. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  124. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  125. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  126. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  127. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  128. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  129. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  130. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  131. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  132. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  133. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  134. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  135. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Es.php ( 3.30 KB )
  136. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  137. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  138. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  139. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  140. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  141. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  142. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  143. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  144. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/runtime/temp/c935550e3e8a3a4c27dd94e439343fdf.php ( 31.50 KB )
  145. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000853s ] mysql:host=127.0.0.1;port=3306;dbname=wenku;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000877s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000587s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.001713s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000555s ]
  6. SELECT * FROM `set` [ RunTime:0.000334s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000563s ]
  8. SELECT * FROM `article` WHERE `id` = 867918 LIMIT 1 [ RunTime:0.005770s ]
  9. UPDATE `article` SET `lasttime` = 1784778164 WHERE `id` = 867918 [ RunTime:0.003947s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 64 LIMIT 1 [ RunTime:0.002295s ]
  11. SELECT * FROM `article` WHERE `id` < 867918 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.001659s ]
  12. SELECT * FROM `article` WHERE `id` > 867918 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000488s ]
  13. SELECT * FROM `article` WHERE `id` < 867918 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.003768s ]
  14. SELECT * FROM `article` WHERE `id` < 867918 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.014940s ]
  15. SELECT * FROM `article` WHERE `id` < 867918 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.002848s ]
0.201938s