| 10 | #include "quantization.h" |
| 11 | |
| 12 | std::vector<at::Tensor> quantize_kernel(at::Tensor& input_vals, |
| 13 | int groups, |
| 14 | int numBits, |
| 15 | quantize::Type quantType) |
| 16 | { |
| 17 | auto dtype = at::kFloat; |
| 18 | auto params_options = at::TensorOptions() |
| 19 | .dtype(dtype) |
| 20 | .layout(at::kStrided) |
| 21 | .device(at::kCUDA) |
| 22 | .requires_grad(false); |
| 23 | const int param_elems = (quantize::requires_offset(quantType)) ? 2 : 1; |
| 24 | auto params = torch::empty({groups, param_elems}, params_options); |
| 25 | |
| 26 | auto output_options = at::TensorOptions() |
| 27 | .dtype(at::kChar) |
| 28 | .layout(at::kStrided) |
| 29 | .device(at::kCUDA) |
| 30 | .requires_grad(false); |
| 31 | |
| 32 | auto output_sizes = input_vals.sizes().vec(); |
| 33 | output_sizes[output_sizes.size() - 1] /= numBits == 8 ? 1 : 2; |
| 34 | auto output = torch::empty(output_sizes, output_options); |
| 35 | |
| 36 | const int elems_per_group = at::numel(input_vals) / groups; |
| 37 | |
| 38 | launch_quant((int8_t*)output.data_ptr(), |
| 39 | (float*)params.data_ptr(), |
| 40 | (__half*)input_vals.data_ptr(), |
| 41 | groups, |
| 42 | elems_per_group, |
| 43 | numBits, |
| 44 | quantType, |
| 45 | at::cuda::getCurrentCUDAStream()); |
| 46 | |
| 47 | return {output, params}; |
| 48 | } |
| 49 | |
| 50 | template <typename T> |
| 51 | at::Tensor dequantize(at::Tensor& quantized_data, |
nothing calls this directly
no test coverage detected