| 922 | } // namespace |
| 923 | |
| 924 | void QuantizedMatmul::eval_cpu(const std::vector<array>& inputs, array& out) { |
| 925 | auto& x_pre = inputs[0]; |
| 926 | auto& w_pre = inputs[1]; |
| 927 | auto& scales_pre = inputs[2]; |
| 928 | |
| 929 | auto& encoder = cpu::get_command_encoder(stream()); |
| 930 | auto x = ensure_row_contiguous(x_pre, encoder, stream()); |
| 931 | auto w = ensure_row_contiguous(w_pre, encoder, stream()); |
| 932 | auto scales = ensure_row_contiguous(scales_pre, encoder, stream()); |
| 933 | |
| 934 | out.set_data(allocator::malloc(out.nbytes())); |
| 935 | |
| 936 | encoder.set_input_array(x); |
| 937 | encoder.set_input_array(w); |
| 938 | encoder.set_input_array(scales); |
| 939 | encoder.set_output_array(out); |
| 940 | if (mode_ == QuantizationMode::Affine) { |
| 941 | auto biases = ensure_row_contiguous(inputs[3], encoder, stream()); |
| 942 | encoder.set_input_array(biases); |
| 943 | encoder.dispatch([out = array::unsafe_weak_copy(out), |
| 944 | x = array::unsafe_weak_copy(x), |
| 945 | w = array::unsafe_weak_copy(w), |
| 946 | scales = array::unsafe_weak_copy(scales), |
| 947 | biases = array::unsafe_weak_copy(biases), |
| 948 | group_size_ = group_size_, |
| 949 | bits_ = bits_, |
| 950 | transpose_ = transpose_]() mutable { |
| 951 | _qmm_dispatch(out, x, w, scales, biases, group_size_, bits_, transpose_); |
| 952 | }); |
| 953 | } else { |
| 954 | encoder.dispatch([out = array::unsafe_weak_copy(out), |
| 955 | x = array::unsafe_weak_copy(x), |
| 956 | w = array::unsafe_weak_copy(w), |
| 957 | scales = array::unsafe_weak_copy(scales), |
| 958 | group_size_ = group_size_, |
| 959 | bits_ = bits_, |
| 960 | transpose_ = transpose_]() mutable { |
| 961 | fp_qmm_dispatch(out, x, w, scales, group_size_, bits_, transpose_); |
| 962 | }); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | void GatherQMM::eval_cpu(const std::vector<array>& inputs, array& out) { |
| 967 | auto& x_pre = inputs[0]; |
nothing calls this directly
no test coverage detected