gguf-kernels / torch-ext /torch_binding.cpp
marcsun13's picture
marcsun13 HF Staff
GGUF kernels: dequantize + fused gemv over packed blocks, 9 CUDA variants
2c20074 verified
Raw
History Blame Contribute Delete
752 Bytes
#include <torch/library.h>
#include "registration.h"
#include "torch_binding.h"
TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) {
ops.def("dequantize(Tensor blocks, int ggml_type, int rows, int cols, ScalarType dtype) -> Tensor");
ops.def("mul_mat_vec(Tensor blocks, Tensor x, int ggml_type, int out_features) -> Tensor");
// The schema is the same for every backend; only the implementation differs.
#if defined(CUDA_KERNEL) || defined(ROCM_KERNEL)
ops.impl("dequantize", torch::kCUDA, &dequantize);
ops.impl("mul_mat_vec", torch::kCUDA, &mul_mat_vec);
#elif defined(METAL_KERNEL)
ops.impl("dequantize", torch::kMPS, &dequantize);
ops.impl("mul_mat_vec", torch::kMPS, &mul_mat_vec);
#endif
}
REGISTER_EXTENSION(TORCH_EXTENSION_NAME)