Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEA] Support for (u)int8 matrix in row_normalize #2291

Open
enp1s0 opened this issue May 6, 2024 · 0 comments
Open

[FEA] Support for (u)int8 matrix in row_normalize #2291

enp1s0 opened this issue May 6, 2024 · 0 comments
Labels
feature request New feature or request

Comments

@enp1s0
Copy link
Member

enp1s0 commented May 6, 2024

Overflow can occur when T = (u)int8 in the row_normalize function because the accumulator data type is also T.

RAFT_KERNEL __launch_bounds__(Policy::ThreadsPerBlock)
coalesced_normalize_thin_kernel(Type* out,
const Type* in,
IdxType D,
IdxType N,
Type init,
MainLambda main_op,
ReduceLambda reduce_op,
FinalLambda fin_op,
Type eps)
{
IdxType i = threadIdx.y + (Policy::RowsPerBlock * static_cast<IdxType>(blockIdx.x));
if (i >= N) return;
Type acc = init;
for (IdxType j = threadIdx.x; j < D; j += Policy::LogicalWarpSize) {
Type val = in[j + D * i];
acc = reduce_op(acc, main_op(val, j));
}
acc = raft::logicalWarpReduce<Policy::LogicalWarpSize>(acc, reduce_op);
acc = fin_op(acc);
if (acc <= eps) return;
for (IdxType j = threadIdx.x; j < D; j += Policy::LogicalWarpSize) {
out[j + D * i] = in[j + D * i] / acc;
}
}

Required in this PR: #2287 (comment)

modifications

  • Update accumulator data type (e.g. int32_t, float)
    • Template parameter?
  • Add scaling method (e.g. [scale](int8_t elm, int32_t norm){return min(INT8_MAX, max(INT8_MIN, elm * scale / norm));})
    • This is required since adjusting the norm to 1 is not appropriate for integer matrices.
    • Overflow avoidance is also required.
@enp1s0 enp1s0 added the feature request New feature or request label May 6, 2024
@enp1s0 enp1s0 assigned enp1s0 and unassigned enp1s0 May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant