7#if defined(WINDOWS_CUDA_12_1_WORKAROUND) && defined(_WIN32)
11#include <cuda_runtime.h>
71 std::string(
file) +
" " + std::to_string(
line);
81#define gpuErrchk(ans) \
82 { gpuAssert((ans), __FILE__, __LINE__); }
180 const float*
A,
int lda,
181 const float*
B,
int ldb,
394 int token_id,
int hidden_size,
409 int token_id,
int hidden_size,
int vocab_size,
486 int intermediate_size,
static void error(const std::string &message)
void gemm_rm_f32_cuda(cublasHandle_t handle, const float *X, const float *W, float *Y, int T, int O, int I, cudaStream_t stream)
void moe_ffn_cuda(cublasHandle_t handle, const float *x, int T, int d, int d_ff, int E, int k, bool renorm, const float *router, const float *gate_exps, const float *up_exps, const float *down_exps, float *scratch, float *out, cudaStream_t stream)
void decode_embed_cuda(const float *table_dev, float *out_dev, const int *step_dev, int hidden_size, int vocab_size, cudaStream_t stream)
void add_residual_batch_cuda(float *d_output_batch, const float *d_input_a_batch, const float *d_input_b_batch, int num_tokens, int hidden_size, cudaStream_t stream)
void softmax_vector_cuda(const std::vector< float > &x_host, std::vector< float > &out_host, int n)
void matvec_f32_f32_cuda(cublasHandle_t handle, const float *mat_f32_dev, const float *vec_f32_dev, float *out_f32_dev, int rows, int cols, cudaStream_t stream)
Implementation of matrix-vector multiplication with FP32.
void rope_and_update_kv_cache_cuda(float *cache_base_ptr, const float *kv_vector_head, const float *all_freqs_cis_base, int pos, int kv_head_idx, int max_seq_len, int num_kv_heads, int head_dim, cudaStream_t stream)
size_t moe_ffn_scratch_floats(int T, int d, int d_ff, int E, int k)
void kv_write_devpos_cuda(float *k_cache_dev, float *v_cache_dev, const float *k_dev, const float *v_dev, const int *step_dev, int row, cudaStream_t stream)
void rope_cuda(float *x_dev, int num_heads, int head_dim, const float *all_freqs_cis_dev_base, int pos, bool use_adjacent_pairing, cudaStream_t stream)
void attention_cuda_selective_dequant(const float *Q_current_dev, const int8_t *K_quantized_cache_base, const int8_t *V_quantized_cache_base, const float *K_scales_cache_base, const float *V_scales_cache_base, float *selective_k_dequant_buffer, float *selective_v_dequant_buffer, float *out_dev, int num_heads, int current_seq_len, int head_dim, float scale, int cache_max_seq_len, int cache_num_kv_heads, cudaStream_t stream)
void softmax_vector_cuda_optimized(const float *x_dev, float *out_dev, int n, cudaStream_t stream)
void rope_batch_cuda(float *d_q_batch, float *d_k_batch, const float *d_all_freqs_cis_base, int num_tokens, int num_q_heads, int num_kv_heads, int head_dim, int start_pos_in_kv_cache, bool use_adjacent_pairing, cudaStream_t stream)
void convert_fp32_to_bf16_cuda(const float *fp32_in_dev, uint16_t *bf16_out_dev, size_t n_elements, cudaStream_t stream)
void add_residual_cuda(const float *matvec_out_dev, const float *residual_dev, float *result_dev, int n, cudaStream_t stream)
void matvec_bf16_f32_cuda(cublasHandle_t handle, const uint16_t *mat_bf16_dev, const float *vec_f32_dev, float *out_f32_dev, int rows, int cols, bool use_tensor_cores, cudaStream_t stream)
Matrix-vector multiplication with BF16 matrix and FP32 vector/output on GPU.
void swiglu_cuda(const float *gate_dev, const float *up_dev, float *out_dev, int n, cudaStream_t stream)
void decode_attention_tiles(int *min_chunk, int *max_chunks)
void rmsnorm_vector_cuda_optimized(const float *x_dev, const float *weight_dev, float *out_dev, int n, float eps, cudaStream_t stream)
Optimized wrappers using the new high-performance kernels.
void silu_cuda(const std::vector< float > &x_host, std::vector< float > &out_host, int n)
void convert_bf16_to_fp32_cuda(const uint16_t *bf16_in_dev, float *fp32_out_dev, size_t n_elements, cudaStream_t stream)
void attention_devpos_cuda(const float *Q_current_dev, const float *K_layer_cache_base, const float *V_layer_cache_base, float *out_dev, int num_heads, int head_dim, float scale, int cache_max_seq_len, int cache_num_kv_heads, const int *step_dev, cudaStream_t stream)
__global__ void reduce_partial_sums_kernel(const float *partial_sums, float *total_sum_sq_out, int num_partial_sums)
void gemm_bf16_bf16_cuda(cublasHandle_t handle, bool transa_user, bool transb_user, int m_user, int n_user, int k_user, const float *alpha_user, const uint16_t *A_bf16_user, int lda_user, const uint16_t *B_bf16_user, int ldb_user, const float *beta_user, uint16_t *C_bf16_user, int ldc_user, cudaStream_t stream)
void gemm_f32_to_bf16_f32_cuda(cublasHandle_t handle, bool transa_user, bool transb_user, int m_user, int n_user, int k_user, const float *alpha_user, const float *A_f32_user, int lda_user, const uint16_t *B_bf16_user, int ldb_user, const float *beta_user, float *C_f32_user, int ldc_user, cudaStream_t stream)
void rope_devpos_cuda(float *x_dev, int num_heads, int head_dim, const float *all_freqs_cis_dev_base, const int *step_dev, bool use_adjacent_pairing, cudaStream_t stream)
void swiglu_batch_cuda(float *d_out_batch, const float *d_gate_act_batch, const float *d_up_act_batch, int num_tokens, int intermediate_size, cudaStream_t stream)
int decode_attention_kind()
void lookup_embedding_cuda(const void *table_dev, float *output_dev, int token_id, int hidden_size, int vocab_size, bool is_bf16, cudaStream_t stream)
void attention_cuda(const float *Q_current_dev, const float *K_layer_cache_base, const float *V_layer_cache_base, float *out_dev, int num_heads, int current_seq_len, int head_dim, float scale, int cache_max_seq_len, int cache_num_kv_heads, cudaStream_t stream)
__global__ void convert_bf16_to_fp32_kernel(const uint16_t *__restrict__ bf16_in, float *__restrict__ fp32_out, size_t n_elements)
void update_kv_cache_cuda(float *cache_base_ptr, const float *current_kv_head_vector, int pos, int kv_head_idx, int max_seq_len, int num_kv_heads, int head_dim, cudaStream_t stream)
void attention_decode_at_cuda(const float *Q_current_dev, const float *K_layer_cache_base, const float *V_layer_cache_base, float *out_dev, int num_heads, int seq_len, int head_dim, float scale, int cache_max_seq_len, int cache_num_kv_heads, cudaStream_t stream)
__global__ void convert_fp32_to_bf16_kernel(const float *__restrict__ fp32_in, uint16_t *__restrict__ bf16_out, size_t n_elements)
void rmsnorm_vector_cuda(const float *x_dev, const float *weight_dev, float *out_dev, int n, float eps, cudaStream_t stream)
Implementation of RMS normalization with device pointers.
void attention_cuda_optimized(const float *Q_current_dev, const float *K_layer_cache_base, const float *V_layer_cache_base, float *out_dev, int num_heads, int current_seq_len, int head_dim, float scale, int cache_max_seq_len, int cache_num_kv_heads, cudaStream_t stream)
void add_vectors_cuda(const float *a_dev, const float *b_dev, float *result_dev, int n, cudaStream_t stream)
expr::Instr code[expr::kMaxCode]
Logging utilities for the TinyLlama implementation.