Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-cuda/convert.cuh # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-cuda / convert.cuh` 66 lines ยท 2440 bytes Raw Blame History 1 #pragma once 2 #include "common.cuh" 3 4 #define CUDA_DEQUANTIZE_BLOCK_SIZE 256 5 6 template 7 using to_t_cuda_t = void (*)(const void * x, T * y, int64_t k, cudaStream_t stream); 8 9 typedef to_t_cuda_t to_fp32_cuda_t; 10 typedef to_t_cuda_t to_fp16_cuda_t; 11 typedef to_t_cuda_t to_bf16_cuda_t; 12 13 to_fp16_cuda_t ggml_get_to_fp16_cuda(ggml_type type); 14 15 to_bf16_cuda_t ggml_get_to_bf16_cuda(ggml_type type); 16 17 to_fp32_cuda_t ggml_get_to_fp32_cuda(ggml_type type); 18 19 // TODO more general support for non-contiguous inputs 20 21 template 22 using to_t_nc_cuda_t = void (*)(const void * x, T * y, 23 int64_t ne00, int64_t ne01, int64_t ne02, int64_t ne03, 24 int64_t s01, int64_t s02, int64_t s03, cudaStream_t stream); 25 26 typedef to_t_nc_cuda_t to_fp32_nc_cuda_t; 27 typedef to_t_nc_cuda_t to_fp16_nc_cuda_t; 28 typedef to_t_nc_cuda_t to_bf16_nc_cuda_t; 29 30 to_fp32_nc_cuda_t ggml_get_to_fp32_nc_cuda(ggml_type type); 31 to_fp16_nc_cuda_t ggml_get_to_fp16_nc_cuda(ggml_type type); 32 to_bf16_nc_cuda_t ggml_get_to_bf16_nc_cuda(ggml_type type); 33 34 template 35 __host__ __device__ inline dst_t ggml_cuda_cast(src_t x) { 36 if constexpr (std::is_same_v) { 37 return x; 38 } else if constexpr(std::is_same_v) { 39 return __float2bfloat16(float(x)); 40 } else if constexpr(std::is_same_v) { 41 return __bfloat162float(x); 42 } else if constexpr(std::is_same_v && std::is_same_v) { 43 return __float22half2_rn(x); 44 } else if constexpr(std::is_same_v && std::is_same_v) { 45 #ifdef GGML_USE_HIP 46 return make_float2(__bfloat162float(__low2bfloat16(x)), __bfloat162float(__high2bfloat16(x))); 47 #else 48 #if !defined(GGML_USE_MUSA) && __CUDA_ARCH__ >= 800 49 return __bfloat1622float2(x); 50 #else 51 return make_float2(__bfloat162float(x.x), __bfloat162float(x.y)); 52 #endif // !defined(GGML_USE_MUSA) && __CUDA_ARCH__ >= 800 53 #endif // GGML_USE_HIP 54 } else if constexpr(std::is_same_v && std::is_same_v) { 55 // bypass compile error on cuda 12.0.1 56 #ifdef GGML_USE_HIP 57 return __float22bfloat162_rn(x); 58 #else 59 return {x.x, x.y}; 60 #endif // GGML_USE_HIP 61 } else if constexpr(std::is_same_v) { 62 return int32_t(x); 63 } else { 64 return float(x); 65 } 66 }