MCPcopy Create free account
hub / github.com/ml-explore/mlx / eval_cpu

Method eval_cpu

mlx/backend/cpu/quantized.cpp:924–964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

922} // namespace
923
924void 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
966void GatherQMM::eval_cpu(const std::vector<array>& inputs, array& out) {
967 auto& x_pre = inputs[0];

Callers

nothing calls this directly

Calls 15

mallocFunction · 0.85
_qmm_dispatchFunction · 0.85
fp_qmm_dispatchFunction · 0.85
copy_cpuFunction · 0.85
_bs_qmm_dispatchFunction · 0.85
fp_bs_qmm_dispatchFunction · 0.85
is_power_of_2Function · 0.85
set_unary_output_dataFunction · 0.85
set_dataMethod · 0.80
ensure_row_contiguousFunction · 0.70
ToFP8Class · 0.70

Tested by

no test coverage detected