forked from jiuyuan/InfiniTensor
add reshape
This commit is contained in:
parent
e7d34badfb
commit
9db6703b58
|
@ -1 +1 @@
|
||||||
Subproject commit 51d3105277f3774ed31c02ed4cd11fa92925af77
|
Subproject commit b896cec2dba5b8522b141ac4f89eb43074ee1b98
|
|
@ -0,0 +1,71 @@
|
||||||
|
#include "operators/reshape.h"
|
||||||
|
#include "aclnnop/level2/aclnn_copy.h"
|
||||||
|
#include "ascend/ascend_kernel_without_config.h"
|
||||||
|
#include "ascend/ascend_runtime.h"
|
||||||
|
|
||||||
|
namespace infini {
|
||||||
|
|
||||||
|
class CopyAclnn : public ASCENDKernelWithoutConfig {
|
||||||
|
|
||||||
|
void compute(const Operator &_op,
|
||||||
|
const RuntimeObj *_context) const override {
|
||||||
|
auto op = as<MatmulObj>(_op);
|
||||||
|
auto context = dynamic_cast<const ASCENDRuntimeObj *>(_context);
|
||||||
|
|
||||||
|
void *const aData = (op->getInputs(0)->getRawDataPtr<void *>());
|
||||||
|
void *const bData = (op->getInputs(1)->getRawDataPtr<void *>());
|
||||||
|
void *const cData = (op->getOutput()->getRawDataPtr<void *>());
|
||||||
|
|
||||||
|
auto selfD = op->getInputs(0)->getDims();
|
||||||
|
auto selfS = op->getInputs(0)->getStride();
|
||||||
|
auto matD = op->getInputs(1)->getDims();
|
||||||
|
auto matS = op->getInputs(1)->getStride();
|
||||||
|
auto outD = op->getOutput()->getDims();
|
||||||
|
auto outS = op->getOutput()->getStride();
|
||||||
|
|
||||||
|
std::vector<int64_t> selfDim = MycastTo64(selfD);
|
||||||
|
std::vector<int64_t> selfStride = MycastTo64(selfS);
|
||||||
|
std::vector<int64_t> matDim = MycastTo64(matD);
|
||||||
|
std::vector<int64_t> matStride = MycastTo64(matS);
|
||||||
|
std::vector<int64_t> outputDim = MycastTo64(outD);
|
||||||
|
std::vector<int64_t> outputStride = MycastTo64(outS);
|
||||||
|
|
||||||
|
auto selfTensor = aclCreateTensor(
|
||||||
|
selfDim.data(), selfDim.size(), ACL_FLOAT, selfStride.data(), 0,
|
||||||
|
aclFormat::ACL_FORMAT_ND, selfDim.data(), selfDim.size(), aData);
|
||||||
|
auto matTensor = aclCreateTensor(
|
||||||
|
matDim.data(), matDim.size(), ACL_FLOAT, matStride.data(), 0,
|
||||||
|
aclFormat::ACL_FORMAT_ND, matDim.data(), matDim.size(), bData);
|
||||||
|
auto outputTensor =
|
||||||
|
aclCreateTensor(outputDim.data(), outputDim.size(), ACL_FLOAT,
|
||||||
|
outputStride.data(), 0, aclFormat::ACL_FORMAT_ND,
|
||||||
|
outputDim.data(), outputDim.size(), cData);
|
||||||
|
|
||||||
|
uint64_t workspaceSize = 0;
|
||||||
|
aclOpExecutor *executor;
|
||||||
|
|
||||||
|
auto ret = aclnnMatmulGetWorkspaceSize(
|
||||||
|
selfTensor, matTensor, outputTensor, 1, &workspaceSize, &executor);
|
||||||
|
void *workspaceAddr = nullptr;
|
||||||
|
if (workspaceSize > 0) {
|
||||||
|
workspaceAddr = context->getWorkspace(workspaceSize);
|
||||||
|
}
|
||||||
|
assert(ret == ACL_SUCCESS);
|
||||||
|
ret = aclnnMatmul(workspaceAddr, workspaceSize, executor,
|
||||||
|
context->ASCENDHandle());
|
||||||
|
assert(ret == ACL_SUCCESS);
|
||||||
|
|
||||||
|
ret = aclrtSynchronizeStream(context->ASCENDHandle());
|
||||||
|
assert(ret == ACL_SUCCESS);
|
||||||
|
|
||||||
|
// aclDestroyTensor(selfTensor);
|
||||||
|
// aclDestroyTensor(matTensor);
|
||||||
|
// aclDestroyTensor(outputTensor);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
REGISTER_KERNEL(Device::ASCEND, OpType::MatMul, MatmulAclnn,
|
||||||
|
"matmul_ASCEND_float");
|
||||||
|
}; // namespace infini
|
|
@ -43,6 +43,12 @@ TEST(ascend_ElementWise, run) {
|
||||||
0.9820138, 0.9820138, 0.9820138, 0.0179862, 0.0179862,
|
0.9820138, 0.9820138, 0.9820138, 0.0179862, 0.0179862,
|
||||||
0.0179862, 0.0179862, 0.9820138, 0.9820138, 0.9820138,
|
0.0179862, 0.0179862, 0.9820138, 0.9820138, 0.9820138,
|
||||||
0.9820138});
|
0.9820138});
|
||||||
|
testSoftmax<SoftmaxObj>(
|
||||||
|
IncrementalGenerator(), Shape{2, 2, 2, 2}, 2,
|
||||||
|
vector<float>{0.1192029, 0.1192029, 0.8807971, 0.8807971, 0.1192029,
|
||||||
|
0.1192029, 0.8807971, 0.8807971, 0.1192029, 0.1192029,
|
||||||
|
0.8807971, 0.8807971, 0.1192029, 0.1192029, 0.8807971,
|
||||||
|
0.8807971});
|
||||||
testSoftmax<SoftmaxObj>(
|
testSoftmax<SoftmaxObj>(
|
||||||
IncrementalGenerator(), Shape{2, 2, 2, 2}, 3,
|
IncrementalGenerator(), Shape{2, 2, 2, 2}, 3,
|
||||||
vector<float>{0.2689414, 0.7310586, 0.2689414, 0.7310586, 0.2689414,
|
vector<float>{0.2689414, 0.7310586, 0.2689414, 0.7310586, 0.2689414,
|
||||||
|
|
Loading…
Reference in New Issue