Unverified Commit 452049e2 authored by PanZezhong1725's avatar PanZezhong1725 Committed by GitHub
Browse files

Merge pull request #116 from PanZezhong1725/issue/115

issue/115 将matmul改名为gemm
parents 2ede6b81 054763bc
......@@ -49,6 +49,6 @@ jobs:
if: matrix.os != 'windows-latest'
run: |
pip install torch
LD_LIBRARY_PATH=$HOME/.infini/lib python test/infiniop/matmul.py --cpu
LD_LIBRARY_PATH=$HOME/.infini/lib python test/infiniop/gemm.py --cpu
LD_LIBRARY_PATH=$HOME/.infini/lib python test/infiniop/rms_norm.py --cpu
LD_LIBRARY_PATH=$HOME/.infini/lib python test/infiniop/random_sample.py --cpu
......@@ -10,7 +10,7 @@
#include "infiniop/ops/expand.h"
#include "infiniop/ops/gemm.h"
#include "infiniop/ops/global_avg_pool.h"
#include "infiniop/ops/matmul.h"
#include "infiniop/ops/gemm.h"
#include "infiniop/ops/max_pool.h"
#include "infiniop/ops/mlp.h"
#include "infiniop/ops/random_sample.h"
......
......@@ -2,7 +2,7 @@
#define __INFINIOP_ATTENTION_API_H__
#include "../operator_descriptor.h"
#include "matmul.h"
#include "gemm.h"
#include "swiglu.h"
typedef InfiniopDescriptor *infiniopAttentionDescriptor_t;
......
......@@ -3,29 +3,26 @@
#include "../operator_descriptor.h"
typedef InfiniopDescriptor *infiniopGEMMDescriptor_t;
typedef InfiniopDescriptor *infiniopGemmDescriptor_t;
__C __export infiniStatus_t infiniopCreateGEMMDescriptor(infiniopHandle_t handle,
infiniopGEMMDescriptor_t *desc_ptr,
infiniopTensorDescriptor_t y_desc,
infiniopTensorDescriptor_t a_desc,
infiniopTensorDescriptor_t b_desc,
__C __export infiniStatus_t infiniopCreateGemmDescriptor(infiniopHandle_t handle,
infiniopGemmDescriptor_t *desc_ptr,
infiniopTensorDescriptor_t c_desc,
char transA,
char transB);
infiniopTensorDescriptor_t a_desc,
infiniopTensorDescriptor_t b_desc);
__C __export infiniStatus_t infiniopGetGEMMWorkspaceSize(infiniopGEMMDescriptor_t desc, size_t *size);
__C __export infiniStatus_t infiniopGetGemmWorkspaceSize(infiniopGemmDescriptor_t desc, size_t *size);
__C __export infiniStatus_t infiniopGEMM(infiniopGEMMDescriptor_t desc,
__C __export infiniStatus_t infiniopGemm(infiniopGemmDescriptor_t desc,
void *workspace,
size_t workspace_size,
void *y,
void *c,
void const *a,
void const *b,
void const *c,
float alpha,
float beta,
void *stream);
__C __export infiniStatus_t infiniopDestroyGEMMDescriptor(infiniopGEMMDescriptor_t desc);
__C __export infiniStatus_t infiniopDestroyGemmDescriptor(infiniopGemmDescriptor_t desc);
#endif
#ifndef __INFINIOP_MATMUL_API_H__
#define __INFINIOP_MATMUL_API_H__
#include "../operator_descriptor.h"
typedef InfiniopDescriptor *infiniopMatmulDescriptor_t;
__C __export infiniStatus_t infiniopCreateMatmulDescriptor(infiniopHandle_t handle,
infiniopMatmulDescriptor_t *desc_ptr,
infiniopTensorDescriptor_t c_desc,
infiniopTensorDescriptor_t a_desc,
infiniopTensorDescriptor_t b_desc);
__C __export infiniStatus_t infiniopGetMatmulWorkspaceSize(infiniopMatmulDescriptor_t desc, size_t *size);
__C __export infiniStatus_t infiniopMatmul(infiniopMatmulDescriptor_t desc,
void *workspace,
size_t workspace_size,
void *c,
void const *a,
void const *b,
float alpha,
float beta,
void *stream);
__C __export infiniStatus_t infiniopDestroyMatmulDescriptor(infiniopMatmulDescriptor_t desc);
#endif
......@@ -2,7 +2,7 @@
#define __INFINIOP_MLP_API_H__
#include "../operator_descriptor.h"
#include "matmul.h"
#include "gemm.h"
#include "swiglu.h"
typedef InfiniopDescriptor *infiniopMLPDescriptor_t;
......
......@@ -5,7 +5,7 @@
/*
* Declare all the tests here
*/
DECLARE_INFINIOP_TEST(matmul)
DECLARE_INFINIOP_TEST(gemm)
#define REGISTER_INFINIOP_TEST(name) \
{ \
......@@ -18,9 +18,9 @@ DECLARE_INFINIOP_TEST(matmul)
/*
* Register all the tests here
*/
#define TEST_BUILDER_MAPPINGS \
{ \
REGISTER_INFINIOP_TEST(matmul), \
#define TEST_BUILDER_MAPPINGS \
{ \
REGISTER_INFINIOP_TEST(gemm), \
}
namespace infiniop_test {
......
......@@ -4,7 +4,7 @@
#include <iomanip>
#include <iostream>
namespace infiniop_test::matmul {
namespace infiniop_test::gemm {
struct Test::Attributes {
float alpha;
float beta;
......@@ -43,30 +43,30 @@ std::shared_ptr<Test> Test::build(
std::shared_ptr<infiniop_test::Result> Test::run(
infiniopHandle_t handle, infiniDevice_t device, int device_id, size_t warm_ups, size_t iterations) {
infiniopMatmulDescriptor_t op_desc;
infiniopGemmDescriptor_t op_desc;
auto alpha = _attributes->alpha;
auto beta = _attributes->beta;
auto a = _attributes->a->to(device, device_id);
auto b = _attributes->b->to(device, device_id);
auto c = _attributes->c->to(device, device_id);
CHECK_OR(infiniopCreateMatmulDescriptor(handle, &op_desc,
c->desc(),
a->desc(),
b->desc()),
CHECK_OR(infiniopCreateGemmDescriptor(handle, &op_desc,
c->desc(),
a->desc(),
b->desc()),
return TEST_FAILED(OP_CREATION_FAILED, "Failed to create op descriptor."));
size_t workspace_size;
CHECK_OR(infiniopGetMatmulWorkspaceSize(op_desc, &workspace_size),
CHECK_OR(infiniopGetGemmWorkspaceSize(op_desc, &workspace_size),
return TEST_FAILED(OP_CREATION_FAILED, "Failed to get workspace size."));
void *workspace;
CHECK_OR(infinirtMalloc(&workspace, workspace_size),
return TEST_FAILED(OP_CREATION_FAILED, "Failed to allocate workspace."));
CHECK_OR(infiniopMatmul(op_desc, workspace, workspace_size,
c->data(),
a->data(),
b->data(),
alpha,
beta,
nullptr),
CHECK_OR(infiniopGemm(op_desc, workspace, workspace_size,
c->data(),
a->data(),
b->data(),
alpha,
beta,
nullptr),
return TEST_FAILED(OP_EXECUTION_FAILED, "Failed during execution."));
try {
......@@ -83,7 +83,7 @@ std::shared_ptr<infiniop_test::Result> Test::run(
elapsed_time = benchmark(
[=]() {
infiniopMatmul(
infiniopGemm(
op_desc, workspace, workspace_size,
c->data(),
a->data(),
......@@ -91,7 +91,7 @@ std::shared_ptr<infiniop_test::Result> Test::run(
alpha,
beta,
nullptr);
infiniopMatmul(
infiniopGemm(
op_desc, workspace, workspace_size,
c->data(),
a->data(),
......@@ -129,4 +129,4 @@ Test::~Test() {
delete _attributes;
}
} // namespace infiniop_test::matmul
} // namespace infiniop_test::gemm
#include "matmul_ascend.h"
#include "gemm_ascend.h"
#include "../../../devices/ascend/common_ascend.h"
#include <aclnnop/aclnn_matmul.h>
#include <aclnnop/level2/aclnn_gemm.h>
namespace op::matmul::ascend {
namespace op::gemm::ascend {
struct Descriptor::Opaque {
mutable aclOpExecutor *executor;
......@@ -116,4 +116,4 @@ infiniStatus_t Descriptor::calculate(
return INFINI_STATUS_SUCCESS;
}
} // namespace op::matmul::ascend
} // namespace op::gemm::ascend
#ifndef __GEMM_ASCEND_H__
#define __GEMM_ASCEND_H__
#include "../gemm.h"
DESCRIPTOR(ascend)
#endif // __GEMM_ASCEND_H__
#include "matmul_bang.h"
#include "gemm_bang.h"
#include "../../../devices/bang/common_bang.h"
#include <cnnl_extra.h>
namespace op::matmul::bang {
namespace op::gemm::bang {
struct Descriptor::Opaque {
cnnlMatMulDescriptor_t op;
......@@ -157,4 +157,4 @@ infiniStatus_t Descriptor::calculate(
return INFINI_STATUS_SUCCESS;
}
} // namespace op::matmul::bang
} // namespace op::gemm::bang
#ifndef __GEMM_BANG_H__
#define __GEMM_BANG_H__
#include "../gemm.h"
DESCRIPTOR(bang)
#endif // __GEMM_BANG_H__
......@@ -5,7 +5,7 @@
#include "../../tensor.h"
#include <algorithm>
namespace op::matmul {
namespace op::gemm {
struct BlasMatrix {
size_t ndim;
......@@ -120,6 +120,6 @@ struct MatmulInfo {
}
};
} // namespace op::matmul
} // namespace op::gemm
#endif // __BLAS_H__
#include "matmul_cpu.h"
#include "gemm_cpu.h"
#include "../../../devices/cpu/common_cpu.h"
namespace op::matmul::cpu {
namespace op::gemm::cpu {
Descriptor::~Descriptor() = default;
......@@ -95,4 +95,4 @@ infiniStatus_t Descriptor::calculate(
}
}
} // namespace op::matmul::cpu
} // namespace op::gemm::cpu
#ifndef __GEMM_CPU_H__
#define __GEMM_CPU_H__
#include "../gemm.h"
DESCRIPTOR(cpu)
#endif // __GEMM_CPU_H__
#include "../../../devices/cuda/cuda_handle.cuh"
#include "matmul_cuda.cuh"
#include "gemm_cuda.cuh"
namespace op::matmul::cuda {
namespace op::gemm::cuda {
struct Descriptor::Opaque {
std::shared_ptr<device::cuda::Handle::Internal> internal;
......@@ -109,4 +109,4 @@ infiniStatus_t Descriptor::calculate(
return INFINI_STATUS_SUCCESS;
}
} // namespace op::matmul::cuda
} // namespace op::gemm::cuda
#ifndef __GEMM_CUDA_CUH__
#define __GEMM_CUDA_CUH__
#include "../gemm.h"
DESCRIPTOR(cuda)
#endif // __GEMM_CUDA_CUH__
#ifndef __MATMUL_H__
#define __MATMUL_H__
#ifndef __GEMM_H__
#define __GEMM_H__
#include "../../operator.h"
#include "blas.h"
......@@ -46,7 +46,7 @@
#define DESCRIPTOR(NAMESPACE) \
\
namespace op::matmul::NAMESPACE { \
namespace op::gemm::NAMESPACE { \
class Descriptor final : public InfiniopDescriptor { \
struct Opaque; \
Opaque *_opaque; \
......@@ -90,4 +90,4 @@
}; \
}
#endif // __MATMUL_H__
#endif // __GEMM_H__
#include "matmul_kunlun.h"
#include "gemm_kunlun.h"
#include "../../../../utils.h"
#include "../../../devices/kunlun/kunlun_handle.h"
namespace op::matmul::kunlun {
namespace op::gemm::kunlun {
typedef device::kunlun::Handle::Internal HandleInternal;
......@@ -103,12 +103,12 @@ infiniStatus_t Descriptor::calculate(
void *stream) const {
switch (_dtype) {
case INFINI_DTYPE_F16:
return op::matmul::kunlun::calculate<float16>(_info, _opaque->internal, _dtype, c, beta, a, b, alpha, (kunlunStream_t)stream);
return op::gemm::kunlun::calculate<float16>(_info, _opaque->internal, _dtype, c, beta, a, b, alpha, (kunlunStream_t)stream);
case INFINI_DTYPE_F32:
return op::matmul::kunlun::calculate<float>(_info, _opaque->internal, _dtype, c, beta, a, b, alpha, (kunlunStream_t)stream);
return op::gemm::kunlun::calculate<float>(_info, _opaque->internal, _dtype, c, beta, a, b, alpha, (kunlunStream_t)stream);
default:
return INFINI_STATUS_BAD_TENSOR_DTYPE;
}
}
} // namespace op::matmul::kunlun
} // namespace op::gemm::kunlun
#ifndef __GEMM_KUNLUN_H__
#define __GEMM_KUNLUN_H__
#include "../gemm.h"
DESCRIPTOR(kunlun)
#endif // __GEMM_KUNLUN_H__
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment