Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
MatMulImpl.cpp 2.19 KiB
/********************************************************************************
 * Copyright (c) 2023 CEA-List
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 ********************************************************************************/

#include <cassert>
#include <chrono>  // std::chrono::milliseconds
#include <numeric> // std::accumulate
#include <thread>  // std::this_thread::sleep_for
#include <vector>

#include "aidge/operator/MatMul.hpp"
#include "aidge/utils/Types.h"
#include "aidge/backend/cpu/data/GetCPUPtr.h"

#include "aidge/backend/cpu/operator/MatMulImpl.hpp"
#include "aidge/backend/cpu/operator/MatMulImpl_forward_kernels.hpp"

void Aidge::MatMulImpl_cpu::forward()
{
    assert(std::static_pointer_cast<Tensor>(mOp.getRawInput(0)) && "missing input #0");
    assert(std::static_pointer_cast<Tensor>(mOp.getRawInput(1)) && "missing input #1");

    // Find the correct kernel type
    auto kernelFunc = Registrar<MatMulImplForward_cpu>::create(
        {std::static_pointer_cast<Tensor>(mOp.getRawInput(0))->dataType(),
         std::static_pointer_cast<Tensor>(mOp.getRawInput(1))->dataType(),
         std::static_pointer_cast<Tensor>(mOp.getRawOutput(0))->dataType()});

    // Call kernel
    // if (mOp.getInput(0)->nbDims() == 4) {
    //     kernelFunc(
    //         mOp.getStaticAttributes(),
    //         std::static_pointer_cast<Tensor>(mOp.getInput(0))->template dims<4>(),
    //         mOp.getInput(0))->getImpl()->rawPtr(),
    //         mOp.mInputs[1]->getImpl()->rawPtr(),
    //         mOp.mInputs[2]->getImpl()->rawPtr(),
    //         getCPUPtr(mOp.getRawOutput(0));
    // }
    // else
    kernelFunc(
        dynamic_cast<const MatMul_Op&>(mOp).getStaticAttributes(),
        std::static_pointer_cast<Tensor>(mOp.getRawInput(0))->dims()[0],
        std::static_pointer_cast<Tensor>(mOp.getRawInput(0))->size() / std::static_pointer_cast<Tensor>(mOp.getRawInput(0))->dims()[0],
        getCPUPtr(mOp.getRawInput(0)),
        getCPUPtr(mOp.getRawInput(1)),
        getCPUPtr(mOp.getRawOutput(0)));


}