@@ -187,7 +187,7 @@ private:
|
||||
}
|
||||
} else {
|
||||
Cast(xDup, xLocal, AscendC::RoundMode::CAST_NONE, maxLoRARank_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
for (int32_t i = maxLoRARank_; i < NUM_ELEMENTS_PER_REPEAT; i += maxLoRARank_) {
|
||||
for (int32_t j = 0; j < maxLoRARank_; j++) {
|
||||
@@ -219,15 +219,15 @@ private:
|
||||
AscendC::LocalTensor<Y_T> yInLocal = inQueueY_.DeQue<Y_T>();
|
||||
AscendC::LocalTensor<float> yInLocalFP32 = inBufferY_.Get<float>();
|
||||
Cast(yInLocalFP32, yInLocal, AscendC::RoundMode::CAST_NONE, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueY_.FreeTensor(yInLocal);
|
||||
|
||||
Add(yLocal, yLocal, yInLocalFP32, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
AscendC::LocalTensor<Y_T> yOutLocal = outQueueY_.AllocTensor<Y_T>();
|
||||
Cast(yOutLocal, yLocal, AscendC::RoundMode::CAST_RINT, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
outQueueY_.EnQue<Y_T>(yOutLocal);
|
||||
}
|
||||
@@ -243,40 +243,40 @@ private:
|
||||
AscendC::LocalTensor<float> wTmpTensor = tmpBufferW_.Get<float>();
|
||||
|
||||
Cast(wTmpTensor, wLocal, AscendC::RoundMode::CAST_NONE, MASK_COUNT, blockReduceRepeatCount, castParams_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueW_.FreeTensor(wLocal);
|
||||
|
||||
Mul(wTmpTensor, xDup, wTmpTensor, MASK_COUNT, blockReduceRepeatCount, dotProductParams_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
if (maxLoRARank_ == LORA_RANK_8) {
|
||||
BlockReduceSum(yLocal[progress], wTmpTensor, blockReduceRepeatCount, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
} else if (maxLoRARank_ == LORA_RANK_16) {
|
||||
BlockReduceSum(wTmpTensor, wTmpTensor, blockReduceRepeatCount, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
PairReduceSum(yLocal[progress], wTmpTensor, pairReduceRepeat16, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
} else if (maxLoRARank_ == LORA_RANK_32) {
|
||||
BlockReduceSum(wTmpTensor, wTmpTensor, blockReduceRepeatCount, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
PairReduceSum(wTmpTensor, wTmpTensor, pairReduceRepeat16, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
PairReduceSum(yLocal[progress], wTmpTensor, pairReduceRepeat32, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
} else if (maxLoRARank_ == LORA_RANK_64) {
|
||||
BlockReduceSum(wTmpTensor, wTmpTensor, blockReduceRepeatCount, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
BlockReduceSum(yLocal[progress], wTmpTensor, pairReduceRepeat16, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ private:
|
||||
|
||||
// declare all dtype kernel
|
||||
BGMV_EXPAND_TYPE_DECLARE(half)
|
||||
#if (__CCE_AICORE__ >= 220)
|
||||
#if !defined(__CCE_AICORE__) || (__CCE_AICORE__ >= 220)
|
||||
BGMV_EXPAND_TYPE_DECLARE(bfloat16_t)
|
||||
#endif
|
||||
|
||||
@@ -356,8 +356,8 @@ extern void bgmv_expand_impl(AscendType type, void* stream, void* x, void* weigh
|
||||
bgmv_expand_half<<<blockDim, nullptr, stream>>>(x, weight, indices, indicesSize, yIn, yOut, batchSize, numTokensPerCore,
|
||||
maxLoRARank, outputHiddenDim, sliceOffset, outputFullDim);
|
||||
} else if (type == AscendType::BF16) {
|
||||
#if (__CCE_AICORE__ >= 220)
|
||||
bgmv_expand_bfloat16_t<<<blockDim, nullptr, stream>>>(x, weight, indices, indicesSize, yIn, yOut, batchSize,
|
||||
#if !defined(__CCE_AICORE__) || (__CCE_AICORE__ >= 220)
|
||||
bgmv_expand_bfloat16_t<<<blockDim, nullptr, stream>>>(x, weight, indices, indicesSize, yIn, yOut, batchSize,
|
||||
numTokensPerCore, maxLoRARank, outputHiddenDim,
|
||||
sliceOffset, outputFullDim);
|
||||
#endif
|
||||
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
AscendC::LocalTensor<float> xTmpTensor = tmpBufferX_.Get<float>();
|
||||
AscendC::LocalTensor<X_T> xLocal = inQueueX_.DeQue<X_T>();
|
||||
Cast(xTmpTensor, xLocal, AscendC::RoundMode::CAST_NONE, inputHiddenDim_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueX_.FreeTensor(xLocal);
|
||||
}
|
||||
|
||||
@@ -141,20 +141,20 @@ private:
|
||||
AscendC::LocalTensor<X_T> xLocal = inQueueX_.DeQue<X_T>();
|
||||
Cast(xTmpTensor, xLocal, AscendC::RoundMode::CAST_NONE, numElements);
|
||||
Cast(wTmpTensor, wLocal, AscendC::RoundMode::CAST_NONE, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueX_.FreeTensor(xLocal);
|
||||
inQueueW_.FreeTensor(wLocal);
|
||||
} else {
|
||||
Cast(wTmpTensor, wLocal, AscendC::RoundMode::CAST_NONE, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueW_.FreeTensor(wLocal);
|
||||
}
|
||||
// dot product of the one tile of X and W
|
||||
Mul(wTmpTensor, xTmpTensor, wTmpTensor, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
// reduce sum generate one number, which is the summation of all the dot product
|
||||
ReduceSum<float>(wTmpTensor, wTmpTensor, wTmpTensor, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
acc += wTmpTensor.GetValue(0);
|
||||
}
|
||||
@@ -180,7 +180,7 @@ private:
|
||||
AscendC::LocalTensor<Y_T> yOutLocal = outQueueY_.AllocTensor<Y_T>();
|
||||
|
||||
Muls(yOutLocal, yLocal, scale_, maxLoRARank_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
outQueueY_.EnQue<Y_T>(yOutLocal);
|
||||
}
|
||||
@@ -226,7 +226,7 @@ private:
|
||||
|
||||
// declare all dtype kernel
|
||||
BGMV_SHRINK_TYPE_DECLARE(half)
|
||||
#if (__CCE_AICORE__ >= 220)
|
||||
#if !defined(__CCE_AICORE__) || (__CCE_AICORE__ >= 220)
|
||||
BGMV_SHRINK_TYPE_DECLARE(bfloat16_t)
|
||||
#endif
|
||||
|
||||
@@ -240,8 +240,8 @@ extern void bgmv_shrink_impl(AscendType type, void* stream, void* x, void* weigh
|
||||
bgmv_shrink_half<<<blockDim, nullptr, stream>>>(x, weight, indices, indicesSize, y, batchSize, numTokensPerCore,
|
||||
inputHiddenDim, maxLoRARank, scale);
|
||||
} else if (type == AscendType::BF16) {
|
||||
#if (__CCE_AICORE__ >= 220)
|
||||
bgmv_shrink_bfloat16_t<<<blockDim, nullptr, stream>>>(x, weight, indices, indicesSize, y, batchSize, numTokensPerCore,
|
||||
#if !defined(__CCE_AICORE__) || (__CCE_AICORE__ >= 220)
|
||||
bgmv_shrink_bfloat16_t<<<blockDim, nullptr, stream>>>(x, weight, indices, indicesSize, y, batchSize, numTokensPerCore,
|
||||
inputHiddenDim, maxLoRARank, scale);
|
||||
#endif
|
||||
} else {
|
||||
|
||||
15
csrc/kernels/math_utils.h
Normal file
15
csrc/kernels/math_utils.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef KERNEL_MATH_UTILS_H
|
||||
#define KERNEL_MATH_UTILS_H
|
||||
#include <cstdint>
|
||||
|
||||
namespace device_utils {
|
||||
|
||||
template <typename T, T roundVal>
|
||||
__aicore__ __force_inline__ T RoundUp(const T &val)
|
||||
{
|
||||
return (val + roundVal - 1) / roundVal * roundVal;
|
||||
}
|
||||
|
||||
}; // namespace device_utils
|
||||
|
||||
#endif
|
||||
@@ -198,7 +198,7 @@ private:
|
||||
}
|
||||
} else {
|
||||
Cast(xDup, xLocal, AscendC::RoundMode::CAST_NONE, maxLoRARank_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
for (int32_t i = maxLoRARank_; i < NUM_ELEMENTS_PER_REPEAT; i += maxLoRARank_) {
|
||||
for (int32_t j = 0; j < maxLoRARank_; j++) {
|
||||
@@ -230,15 +230,15 @@ private:
|
||||
AscendC::LocalTensor<Y_T> yInLocal = inQueueY_.DeQue<Y_T>();
|
||||
AscendC::LocalTensor<float> yInLocalFP32 = inBufferY_.Get<float>();
|
||||
Cast(yInLocalFP32, yInLocal, AscendC::RoundMode::CAST_NONE, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueY_.FreeTensor(yInLocal);
|
||||
|
||||
Add(yLocal, yLocal, yInLocalFP32, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
AscendC::LocalTensor<Y_T> yOutLocal = outQueueY_.AllocTensor<Y_T>();
|
||||
Cast(yOutLocal, yLocal, AscendC::RoundMode::CAST_RINT, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
outQueueY_.EnQue<Y_T>(yOutLocal);
|
||||
}
|
||||
@@ -254,40 +254,40 @@ private:
|
||||
AscendC::LocalTensor<float> wTmpTensor = tmpBufferW_.Get<float>();
|
||||
|
||||
Cast(wTmpTensor, wLocal, AscendC::RoundMode::CAST_NONE, MASK_COUNT, blockReduceRepeatCount, castParams_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueW_.FreeTensor(wLocal);
|
||||
|
||||
Mul(wTmpTensor, xDup, wTmpTensor, MASK_COUNT, blockReduceRepeatCount, dotProductParams_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
if (maxLoRARank_ == LORA_RANK_8) {
|
||||
BlockReduceSum(yLocal[progress], wTmpTensor, blockReduceRepeatCount, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
} else if (maxLoRARank_ == LORA_RANK_16) {
|
||||
BlockReduceSum(wTmpTensor, wTmpTensor, blockReduceRepeatCount, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
PairReduceSum(yLocal[progress], wTmpTensor, pairReduceRepeat16, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
} else if (maxLoRARank_ == LORA_RANK_32) {
|
||||
BlockReduceSum(wTmpTensor, wTmpTensor, blockReduceRepeatCount, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
PairReduceSum(wTmpTensor, wTmpTensor, pairReduceRepeat16, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
PairReduceSum(yLocal[progress], wTmpTensor, pairReduceRepeat32, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
} else if (maxLoRARank_ == LORA_RANK_64) {
|
||||
BlockReduceSum(wTmpTensor, wTmpTensor, blockReduceRepeatCount, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
BlockReduceSum(yLocal[progress], wTmpTensor, pairReduceRepeat16, MASK_COUNT,
|
||||
reduceSumParams_.dstRepStride, reduceSumParams_.srcBlkStride, reduceSumParams_.srcRepStride);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ private:
|
||||
|
||||
// declare all dtype kernel
|
||||
SGMV_EXPAND_TYPE_DECLARE(half)
|
||||
#if (__CCE_AICORE__ >= 220)
|
||||
#if !defined(__CCE_AICORE__) || (__CCE_AICORE__ >= 220)
|
||||
SGMV_EXPAND_TYPE_DECLARE(bfloat16_t)
|
||||
#endif
|
||||
|
||||
@@ -375,8 +375,8 @@ extern void sgmv_expand_impl(AscendType type, void* stream, void* x, void* weigh
|
||||
numTokensPerCore, maxLoRARank, outputHiddenDim, sliceOffset,
|
||||
outputFullDim);
|
||||
} else if (type == AscendType::BF16) {
|
||||
#if (__CCE_AICORE__ >= 220)
|
||||
sgmv_expand_bfloat16_t<<<blockDim, nullptr, stream>>>(x, weight, loraIndices, loraIndicesSize,
|
||||
#if !defined(__CCE_AICORE__) || (__CCE_AICORE__ >= 220)
|
||||
sgmv_expand_bfloat16_t<<<blockDim, nullptr, stream>>>(x, weight, loraIndices, loraIndicesSize,
|
||||
seqLen, seqLenSize, yIn, yOut, batchSize,
|
||||
numTokensPerCore, maxLoRARank, outputHiddenDim,
|
||||
sliceOffset, outputFullDim);
|
||||
|
||||
@@ -94,7 +94,7 @@ private:
|
||||
AscendC::LocalTensor<float> xTmpTensor = tmpBufferX_.Get<float>();
|
||||
AscendC::LocalTensor<X_T> xLocal = inQueueX_.DeQue<X_T>();
|
||||
Cast(xTmpTensor, xLocal, AscendC::RoundMode::CAST_NONE, inputHiddenDim_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueX_.FreeTensor(xLocal);
|
||||
}
|
||||
|
||||
@@ -153,20 +153,20 @@ private:
|
||||
AscendC::LocalTensor<X_T> xLocal = inQueueX_.DeQue<X_T>();
|
||||
Cast(xTmpTensor, xLocal, AscendC::RoundMode::CAST_NONE, numElements);
|
||||
Cast(wTmpTensor, wLocal, AscendC::RoundMode::CAST_NONE, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueX_.FreeTensor(xLocal);
|
||||
inQueueW_.FreeTensor(wLocal);
|
||||
} else {
|
||||
Cast(wTmpTensor, wLocal, AscendC::RoundMode::CAST_NONE, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
inQueueW_.FreeTensor(wLocal);
|
||||
}
|
||||
// dot product of the one tile of X and W
|
||||
Mul(wTmpTensor, xTmpTensor, wTmpTensor, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
// reduce sum generate one number, which is the summation of all the dot product
|
||||
ReduceSum<float>(wTmpTensor, wTmpTensor, wTmpTensor, numElements);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
acc += wTmpTensor.GetValue(0);
|
||||
}
|
||||
@@ -192,7 +192,7 @@ private:
|
||||
AscendC::LocalTensor<Y_T> yOutLocal = outQueueY_.AllocTensor<Y_T>();
|
||||
|
||||
Muls(yOutLocal, yLocal, scale_, maxLoRARank_);
|
||||
pipe_barrier(PIPE_V);
|
||||
AscendC::PipeBarrier<PIPE_V>();
|
||||
|
||||
outQueueY_.EnQue<Y_T>(yOutLocal);
|
||||
}
|
||||
@@ -242,7 +242,7 @@ private:
|
||||
|
||||
// declare all dtype kernel
|
||||
SGMV_SHRINK_TYPE_DECLARE(half)
|
||||
#if (__CCE_AICORE__ >= 220)
|
||||
#if !defined(__CCE_AICORE__) || (__CCE_AICORE__ >= 220)
|
||||
SGMV_SHRINK_TYPE_DECLARE(bfloat16_t)
|
||||
#endif
|
||||
|
||||
@@ -260,8 +260,8 @@ extern void sgmv_shrink_impl(AscendType type, void* stream, void* x, void* weigh
|
||||
numTokensPerCore, inputHiddenDim, maxLoRARank,
|
||||
scale);
|
||||
} else if (type == AscendType::BF16) {
|
||||
#if (__CCE_AICORE__ >= 220)
|
||||
sgmv_shrink_bfloat16_t<<<blockDim, nullptr, stream>>>(x, weight, loraIndices, loraIndicesSize,
|
||||
#if !defined(__CCE_AICORE__) || (__CCE_AICORE__ >= 220)
|
||||
sgmv_shrink_bfloat16_t<<<blockDim, nullptr, stream>>>(x, weight, loraIndices, loraIndicesSize,
|
||||
seqLen, seqLenSize,
|
||||
y, batchSize,
|
||||
numTokensPerCore, inputHiddenDim, maxLoRARank,
|
||||
|
||||
Reference in New Issue
Block a user