TensorRT-LLMs/cpp/tensorrt_llm/plugins/common/pluginUtils.h
Kaiyu Xie f430a4b447
Update TensorRT-LLM (#1688)
* Update TensorRT-LLM

---------

Co-authored-by: IbrahimAmin <ibrahimamin532@gmail.com>
Co-authored-by: Fabian Joswig <fjosw@users.noreply.github.com>
Co-authored-by: Pzzzzz <hello-cd.plus@hotmail.com>
Co-authored-by: CoderHam <hemant@cohere.com>
Co-authored-by: Konstantin Lopuhin <kostia.lopuhin@gmail.com>
2024-05-28 20:07:49 +08:00

72 lines
2.0 KiB
C++

/*
* SPDX-FileCopyrightText: Copyright (c) 1993-2024 NVIDIA CORPORATION &
* AFFILIATES. All rights reserved. SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <NvInferRuntime.h>
namespace tensorrt_llm::plugins::utils
{
using DimType64 = int64_t;
inline DimType64 computeMDimension(bool transA, nvinfer1::Dims const& dims)
{
DimType64 M{1};
if (transA)
{
for (int i = dims.nbDims - 1; i > 0; --i)
{
M *= dims.d[i];
}
}
else
{
for (int i = 0; i < dims.nbDims - 1; ++i)
{
M *= dims.d[i];
}
}
return M;
}
inline DimType64 computeNDimension(bool transB, nvinfer1::Dims const& dims)
{
DimType64 N{1};
if (transB)
{
for (int32_t i = 0; i < dims.nbDims - 1; ++i)
{
N *= dims.d[i];
}
}
else
{
for (int32_t i = dims.nbDims - 1; i > 0; --i)
{
N *= dims.d[i];
}
}
return N;
}
#define TLLM_INT32_CAST(value) \
((value > 0x7FFFFFFFLL || value < -0x80000000LL) \
? (TLLM_LOG_ERROR("Value of " #value " is out of range for int32_t"), 0) \
: static_cast<int32_t>(value))
} // namespace tensorrt_llm::plugins::utils