Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions python/sglang/jit_kernel/include/sgl_kernel/math.cuh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once
#include <sgl_kernel/type.cuh>

#include <cmath>

namespace device::math {

inline constexpr float log2e = 1.44269504088896340736f;
Expand Down Expand Up @@ -35,16 +33,19 @@ SGL_DEVICE T rsqrt(T a) {
return dtype_trait<T>::rsqrt(a);
}

SGL_DEVICE float exp(float a) {
return ::expf(a);
template <typename T>
SGL_DEVICE T exp(T a) {
return dtype_trait<T>::exp(a);
}

SGL_DEVICE float sin(float a) {
return ::sinf(a);
template <typename T>
SGL_DEVICE T sin(T a) {
return dtype_trait<T>::sin(a);
}

SGL_DEVICE float cos(float a) {
return ::cosf(a);
template <typename T>
SGL_DEVICE T cos(T a) {
return dtype_trait<T>::cos(a);
}

} // namespace device::math
3 changes: 3 additions & 0 deletions python/sglang/jit_kernel/include/sgl_kernel/type.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ SGL_REGISTER_DTYPE_TRAIT(
SGL_REGISTER_UNARY_FUNCTION(abs, fabsf);
SGL_REGISTER_UNARY_FUNCTION(sqrt, sqrtf);
SGL_REGISTER_UNARY_FUNCTION(rsqrt, rsqrtf);
SGL_REGISTER_UNARY_FUNCTION(exp, expf);
SGL_REGISTER_UNARY_FUNCTION(sin, sinf);
SGL_REGISTER_UNARY_FUNCTION(cos, cosf);
SGL_REGISTER_BINARY_FUNCTION(max, fmaxf);
SGL_REGISTER_BINARY_FUNCTION(min, fminf););
SGL_REGISTER_DTYPE_TRAIT(fp16_t, fp16x2_t);
Expand Down
Loading