#include <cuda_runtime.h>
#include <cuda_fp16.h>
#include <iostream>
// constants for approximating the normal cdf
// gelu ->gelu_fast
constexpr static float A = 0.5;
constexpr static float B = 0.7978845608028654;   // sqrt(2.0/M_PI)
constexpr static float C = 0.035677408136300125; // 0.044715 * sqrt(2.0/M_PI)


template <typename T>
__global__
void add_bias_gelu(T* out, const T* bias, int m, int n){
  int idx = n * blockIdx.x + blockIdx.y * blockDim.x + threadIdx.x;
  int bias_idx = blockIdx.y * blockDim.x + threadIdx.x;

  if (idx < m * n){
    T in = out[idx] + bias[bias_idx];
    T cdf = A + A * tanh(in * (C * in * in + B));
    out[idx] = in * cdf;
  }
}

template <>
__global__
void add_bias_gelu<half>(half* out, const half* bias, int m, int n){

  const half2 A2 = __floats2half2_rn(A, A);
  const half2 B2 = __floats2half2_rn(B, B);
  const half2 C2 = __floats2half2_rn(C, C);

  half2 * out_ptr = (half2 *)out;
  half2 * bias_ptr = (half2 *)bias;

  int idx = n * blockIdx.x + blockIdx.y * blockDim.x + threadIdx.x;
  int bias_idx = blockIdx.y * blockDim.x + threadIdx.x;

  if (idx < m * n ){
    half2 in = out_ptr[idx] + bias_ptr[bias_idx];
    half2 tmp = in * (C2 * in * in + B2);
    float x = tanh(__half2float(tmp.x));
    float y = tanh(__half2float(tmp.y));
    half2 cdf = A2 + A2 * make_half2(x, y);
    out_ptr[idx] = in * cdf;
  }
}

template <typename T>
__global__
void add_bias_relu(T* out, const T* bias, int m, int n){
    int idx = n * blockIdx.x + blockIdx.y * blockDim.x + threadIdx.x;
    int bias_idx = blockIdx.y * blockDim.x + threadIdx.x;

    if (idx < m * n){
        T val = out[idx] + bias[bias_idx];
        out[idx] = (T)(val > 0.0f ? val : 0.0f);
    }
}

template <>
  __global__ 
void add_bias_relu(half* out, const half* bias, int m, int n){
    int idx =  n * blockIdx.x + blockIdx.y * blockDim.x + threadIdx.x;
    int bias_idx = blockIdx.y * blockDim.x + threadIdx.x;

    half2 * out_ptr = (half2*)out;
    half2 * bias_ptr = (half2*)bias;
    if (bias_idx < n && idx < m * n){
        half2 val = __hadd2(out_ptr[idx], bias_ptr[bias_idx]);
        val.x = val.x > (half)0.0f ? val.x : (half)0.0f;
        val.y = val.y > (half)0.0f ? val.y : (half)0.0f;
        out_ptr[idx] = val;
    }
}

template<typename T>
void add_bias_act_kernel(void* ffn_inner, const void* bias, int m, int n ,const int act_type ,const cudaStream_t stream)
{
  if (sizeof(T) == sizeof(half)){

    int fold_coeff = 1;
    if (n <= 2048){
      fold_coeff = 1;
    }else if( n <= 4096){
      fold_coeff = 2;
    }else if(n <= 8192){
      fold_coeff = 4;
    }else if(n <= 16384){
      fold_coeff = 8;
    }else if(n <= 16384 * 2){
      fold_coeff = 16;
    }else if(n <= 16384 * 4){
      fold_coeff = 32;
    }
  
    dim3 grid(m, fold_coeff);
    dim3 block(n / fold_coeff);
  

    block.x /= 2;
    if (act_type == 0){
      add_bias_relu<T><<<grid, block, 0, stream>>>((T*)ffn_inner, (T*)bias, m, n / 2);
    }else if(act_type == 1){
      add_bias_gelu<T><<<grid, block, 0, stream>>>((T*)ffn_inner, (T*)bias, m, n / 2);
    }else{
      std::cerr << "unsupported activation " << std::endl;
    }
  } else {

    int fold_coeff = 1;
    if (n <= 1024){
      fold_coeff = 1;
    }else if( n <= 2048){
      fold_coeff = 2;
    }else if(n <= 4096){
      fold_coeff = 4;
    }else if(n <= 8192){
      fold_coeff = 8;
    }else if(n <= 16384){
      fold_coeff = 16;
    }else if(n <= 16384 * 2){
      fold_coeff = 32;
    }else if (n <= 16384 * 4){
      fold_coeff = 64;
    }
  
    dim3 grid(m, fold_coeff);
    dim3 block(n / fold_coeff);
  

    if (act_type == 0){
      add_bias_relu<T><<<grid, block, 0, stream>>>((T*)ffn_inner, (T*)bias, m, n);
    }else if(act_type == 1){
      add_bias_gelu<T><<<grid, block, 0, stream>>>((T*)ffn_inner, (T*)bias, m, n);
    }else {
      std::cerr << "unsupported activation " << std::endl;
    }
  }
}


template void add_bias_act_kernel<float>(void* ffn_inner, const void* bias, const int m, const int n ,const int act_type ,const cudaStream_t stream);
template void add_bias_act_kernel<half>(void* ffn_inner, const void* bias, const int m, const int n ,const int act_type,const cudaStream_t stream);


	.file	"tmpxft_002a5a4a_00000000-6_activation_kernel.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4018:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4018:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_ZL45__device_stub__Z13add_bias_geluIfEvPT_PKS0_iiPfPKfii, @function
_ZL45__device_stub__Z13add_bias_geluIfEvPT_PKS0_iiPfPKfii:
.LFB4046:
	.cfi_startproc
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z13add_bias_geluIfEvPT_PKS0_ii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4046:
	.size	_ZL45__device_stub__Z13add_bias_geluIfEvPT_PKS0_iiPfPKfii, .-_ZL45__device_stub__Z13add_bias_geluIfEvPT_PKS0_iiPfPKfii
	.section	.text._Z13add_bias_geluIfEvPT_PKS0_ii,"axG",@progbits,_Z13add_bias_geluIfEvPT_PKS0_ii,comdat
	.weak	_Z13add_bias_geluIfEvPT_PKS0_ii
	.type	_Z13add_bias_geluIfEvPT_PKS0_ii, @function
_Z13add_bias_geluIfEvPT_PKS0_ii:
.LFB4353:
	.cfi_startproc
	endbr64
	jmp	_ZL45__device_stub__Z13add_bias_geluIfEvPT_PKS0_iiPfPKfii
	.cfi_endproc
.LFE4353:
	.size	_Z13add_bias_geluIfEvPT_PKS0_ii, .-_Z13add_bias_geluIfEvPT_PKS0_ii
	.text
	.type	_ZL51__device_stub__Z13add_bias_geluI6__halfEvPT_PKS1_iiP6__halfPKS_ii, @function
_ZL51__device_stub__Z13add_bias_geluI6__halfEvPT_PKS1_iiP6__halfPKS_ii:
.LFB4040:
	.cfi_startproc
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z13add_bias_geluI6__halfEvPT_PKS1_ii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L8:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4040:
	.size	_ZL51__device_stub__Z13add_bias_geluI6__halfEvPT_PKS1_iiP6__halfPKS_ii, .-_ZL51__device_stub__Z13add_bias_geluI6__halfEvPT_PKS1_iiP6__halfPKS_ii
	.globl	_Z13add_bias_geluI6__halfEvPT_PKS1_ii
	.type	_Z13add_bias_geluI6__halfEvPT_PKS1_ii, @function
_Z13add_bias_geluI6__halfEvPT_PKS1_ii:
.LFB4011:
	.cfi_startproc
	endbr64
	jmp	_ZL51__device_stub__Z13add_bias_geluI6__halfEvPT_PKS1_iiP6__halfPKS_ii
	.cfi_endproc
.LFE4011:
	.size	_Z13add_bias_geluI6__halfEvPT_PKS1_ii, .-_Z13add_bias_geluI6__halfEvPT_PKS1_ii
	.type	_ZL51__device_stub__Z13add_bias_reluI6__halfEvPT_PKS1_iiP6__halfPKS_ii, @function
_ZL51__device_stub__Z13add_bias_reluI6__halfEvPT_PKS1_iiP6__halfPKS_ii:
.LFB4042:
	.cfi_startproc
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z13add_bias_reluI6__halfEvPT_PKS1_ii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L13:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4042:
	.size	_ZL51__device_stub__Z13add_bias_reluI6__halfEvPT_PKS1_iiP6__halfPKS_ii, .-_ZL51__device_stub__Z13add_bias_reluI6__halfEvPT_PKS1_iiP6__halfPKS_ii
	.globl	_Z13add_bias_reluI6__halfEvPT_PKS1_ii
	.type	_Z13add_bias_reluI6__halfEvPT_PKS1_ii, @function
_Z13add_bias_reluI6__halfEvPT_PKS1_ii:
.LFB4014:
	.cfi_startproc
	endbr64
	jmp	_ZL51__device_stub__Z13add_bias_reluI6__halfEvPT_PKS1_iiP6__halfPKS_ii
	.cfi_endproc
.LFE4014:
	.size	_Z13add_bias_reluI6__halfEvPT_PKS1_ii, .-_Z13add_bias_reluI6__halfEvPT_PKS1_ii
	.type	_ZL45__device_stub__Z13add_bias_reluIfEvPT_PKS0_iiPfPKfii, @function
_ZL45__device_stub__Z13add_bias_reluIfEvPT_PKS0_iiPfPKfii:
.LFB4044:
	.cfi_startproc
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z13add_bias_reluIfEvPT_PKS0_ii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L18:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4044:
	.size	_ZL45__device_stub__Z13add_bias_reluIfEvPT_PKS0_iiPfPKfii, .-_ZL45__device_stub__Z13add_bias_reluIfEvPT_PKS0_iiPfPKfii
	.section	.text._Z13add_bias_reluIfEvPT_PKS0_ii,"axG",@progbits,_Z13add_bias_reluIfEvPT_PKS0_ii,comdat
	.weak	_Z13add_bias_reluIfEvPT_PKS0_ii
	.type	_Z13add_bias_reluIfEvPT_PKS0_ii, @function
_Z13add_bias_reluIfEvPT_PKS0_ii:
.LFB4352:
	.cfi_startproc
	endbr64
	jmp	_ZL45__device_stub__Z13add_bias_reluIfEvPT_PKS0_iiPfPKfii
	.cfi_endproc
.LFE4352:
	.size	_Z13add_bias_reluIfEvPT_PKS0_ii, .-_Z13add_bias_reluIfEvPT_PKS0_ii
	.section	.rodata._Z19add_bias_act_kernelIfEvPvPKviiiP11CUstream_st.str1.1,"aMS",@progbits,1
.LC0:
	.string	"unsupported activation "
	.section	.text._Z19add_bias_act_kernelIfEvPvPKviiiP11CUstream_st,"axG",@progbits,_Z19add_bias_act_kernelIfEvPvPKviiiP11CUstream_st,comdat
	.weak	_Z19add_bias_act_kernelIfEvPvPKviiiP11CUstream_st
	.type	_Z19add_bias_act_kernelIfEvPvPKviiiP11CUstream_st, @function
_Z19add_bias_act_kernelIfEvPvPKviiiP11CUstream_st:
.LFB4349:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%ecx, %ebx
	movl	$1, %ecx
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	cmpl	$1024, %ebx
	jle	.L24
	movl	$2, %ecx
	cmpl	$2048, %ebx
	jle	.L24
	movl	$4, %ecx
	cmpl	$4096, %ebx
	jle	.L24
	movl	$8, %ecx
	cmpl	$8192, %ebx
	jle	.L24
	movl	$16, %ecx
	cmpl	$16384, %ebx
	jle	.L24
	movl	$32, %ecx
	cmpl	$32768, %ebx
	jle	.L24
	cmpl	$65537, %ebx
	movl	$64, %ecx
	movl	$1, %eax
	cmovge	%eax, %ecx
.L24:
	movl	%ebx, %eax
	movl	%ebp, 8(%rsp)
	cltd
	movl	%ecx, 12(%rsp)
	idivl	%ecx
	movl	%eax, 20(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 24(%rsp)
	testl	%r8d, %r8d
	jne	.L25
	movl	28(%rsp), %ecx
	movq	20(%rsp), %rdx
	xorl	%r8d, %r8d
	movl	$1, %esi
	movq	8(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movl	%ebx, %ecx
	movl	%ebp, %edx
	movq	%r13, %rsi
	popq	%rbx
	.cfi_def_cfa_offset 32
	movq	%r12, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	_ZL45__device_stub__Z13add_bias_reluIfEvPT_PKS0_iiPfPKfii
.L25:
	.cfi_restore_state
	decl	%r8d
	jne	.L28
	movl	28(%rsp), %ecx
	movq	20(%rsp), %rdx
	xorl	%r8d, %r8d
	movl	$1, %esi
	movq	8(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movl	%ebx, %ecx
	movl	%ebp, %edx
	movq	%r13, %rsi
	popq	%rbx
	.cfi_def_cfa_offset 32
	movq	%r12, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	_ZL45__device_stub__Z13add_bias_geluIfEvPT_PKS0_iiPfPKfii
.L28:
	.cfi_restore_state
	leaq	_ZSt4cerr(%rip), %rdi
	leaq	.LC0(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	movq	%rax, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.L23:
	.cfi_restore_state
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4349:
	.size	_Z19add_bias_act_kernelIfEvPvPKviiiP11CUstream_st, .-_Z19add_bias_act_kernelIfEvPvPKviiiP11CUstream_st
	.section	.text._Z19add_bias_act_kernelI6__halfEvPvPKviiiP11CUstream_st,"axG",@progbits,_Z19add_bias_act_kernelI6__halfEvPvPKviiiP11CUstream_st,comdat
	.weak	_Z19add_bias_act_kernelI6__halfEvPvPKviiiP11CUstream_st
	.type	_Z19add_bias_act_kernelI6__halfEvPvPKviiiP11CUstream_st, @function
_Z19add_bias_act_kernelI6__halfEvPvPKviiiP11CUstream_st:
.LFB4350:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%ecx, %ebx
	movl	$1, %ecx
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	cmpl	$2048, %ebx
	jle	.L39
	movl	$2, %ecx
	cmpl	$4096, %ebx
	jle	.L39
	movl	$4, %ecx
	cmpl	$8192, %ebx
	jle	.L39
	movl	$8, %ecx
	cmpl	$16384, %ebx
	jle	.L39
	movl	$16, %ecx
	cmpl	$32768, %ebx
	jle	.L39
	cmpl	$65537, %ebx
	movl	$32, %ecx
	movl	$1, %eax
	cmovge	%eax, %ecx
.L39:
	movl	%ebx, %eax
	movl	%ebp, 8(%rsp)
	cltd
	movl	%ecx, 12(%rsp)
	idivl	%ecx
	movl	$1, 24(%rsp)
	shrl	%eax
	testl	%r8d, %r8d
	jne	.L40
	movl	%eax, 20(%rsp)
	movq	8(%rsp), %rdi
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movq	20(%rsp), %rdx
	movl	$1, %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L38
	movl	%ebx, %eax
	movl	$2, %ecx
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movq	%r13, %rsi
	cltd
	popq	%rbx
	.cfi_def_cfa_offset 32
	movq	%r12, %rdi
	idivl	%ecx
	movl	%ebp, %edx
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	movl	%eax, %ecx
	jmp	_ZL51__device_stub__Z13add_bias_reluI6__halfEvPT_PKS1_iiP6__halfPKS_ii
.L40:
	.cfi_restore_state
	decl	%r8d
	jne	.L43
	movl	%eax, 20(%rsp)
	movq	8(%rsp), %rdi
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movq	20(%rsp), %rdx
	movl	$1, %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L38
	movl	%ebx, %eax
	movl	$2, %ecx
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movq	%r13, %rsi
	cltd
	popq	%rbx
	.cfi_def_cfa_offset 32
	movq	%r12, %rdi
	idivl	%ecx
	movl	%ebp, %edx
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	movl	%eax, %ecx
	jmp	_ZL51__device_stub__Z13add_bias_geluI6__halfEvPT_PKS1_iiP6__halfPKS_ii
.L43:
	.cfi_restore_state
	leaq	_ZSt4cerr(%rip), %rdi
	leaq	.LC0(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	movq	%rax, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.L38:
	.cfi_restore_state
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4350:
	.size	_Z19add_bias_act_kernelI6__halfEvPvPKviiiP11CUstream_st, .-_Z19add_bias_act_kernelI6__halfEvPvPKviiiP11CUstream_st
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"_Z13add_bias_geluIfEvPT_PKS0_ii"
.LC2:
	.string	"_Z13add_bias_reluIfEvPT_PKS0_ii"
.LC3:
	.string	"_Z13add_bias_reluI6__halfEvPT_PKS1_ii"
.LC4:
	.string	"_Z13add_bias_geluI6__halfEvPT_PKS1_ii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4049:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC1(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z13add_bias_geluIfEvPT_PKS0_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC2(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z13add_bias_reluIfEvPT_PKS0_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC3(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z13add_bias_reluI6__halfEvPT_PKS1_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC4(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z13add_bias_geluI6__halfEvPT_PKS1_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4049:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
template <typename T>
void add_bias_act_kernel(void* ffn_inner, const void* bias, int m, int n ,const int act_type ,const hipStream_t stream);
	.text
	.file	"activation_kernel.hip"
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
