|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +#include <cuda.h> |
| 10 | +#include <cuda_runtime.h> |
| 11 | + |
| 12 | +#include <executorch/backends/aoti/utils.h> |
| 13 | +#include <executorch/backends/cuda/runtime/shims/int4mm.h> |
| 14 | +#include <executorch/backends/cuda/runtime/shims/int4mm.cuh> |
| 15 | +#include <executorch/runtime/platform/log.h> |
| 16 | + |
| 17 | +namespace executorch::backends::cuda { |
| 18 | +#ifdef __cplusplus |
| 19 | +extern "C" { |
| 20 | +#endif |
| 21 | + |
| 22 | +AOTITorchError aoti_torch_cuda__weight_int4pack_mm( |
| 23 | + Tensor* self, |
| 24 | + Tensor* mat2, |
| 25 | + int64_t qGroupSize, |
| 26 | + Tensor* qScaleAndZeros, |
| 27 | + Tensor** ret0) { |
| 28 | + // Validate input parameters first |
| 29 | + // Only check for null pointers here, as the actual validation of tensor |
| 30 | + // properties is done in _weight_int4pack_mm_cuda |
| 31 | + ET_CHECK_OR_RETURN_ERROR( |
| 32 | + self != nullptr, |
| 33 | + InvalidArgument, |
| 34 | + "aoti_torch_cuda__weight_int4pack_mm failed: self tensor is null"); |
| 35 | + |
| 36 | + ET_CHECK_OR_RETURN_ERROR( |
| 37 | + mat2 != nullptr, |
| 38 | + InvalidArgument, |
| 39 | + "aoti_torch_cuda__weight_int4pack_mm failed: mat2 tensor is null"); |
| 40 | + |
| 41 | + ET_CHECK_OR_RETURN_ERROR( |
| 42 | + qScaleAndZeros != nullptr, |
| 43 | + InvalidArgument, |
| 44 | + "aoti_torch_cuda__weight_int4pack_mm failed: qScaleAndZeros tensor is null"); |
| 45 | + |
| 46 | + ET_CHECK_OR_RETURN_ERROR( |
| 47 | + ret0 != nullptr, |
| 48 | + InvalidArgument, |
| 49 | + "aoti_torch_cuda__weight_int4pack_mm failed: ret0 is null"); |
| 50 | + |
| 51 | + *ret0 = _weight_int4pack_mm_cuda(*self, *mat2, qGroupSize, *qScaleAndZeros); |
| 52 | + ET_CUDA_KERNEL_LAUNCH_CHECK_OR_RETURN_ERROR(); |
| 53 | + return Error::Ok; |
| 54 | +} |
| 55 | + |
| 56 | +#ifdef __cplusplus |
| 57 | +} |
| 58 | +#endif |
| 59 | +} // namespace executorch::backends::cuda |
0 commit comments