Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

国产硬件适配 #63

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
1 change: 1 addition & 0 deletions src/02hardware/src/device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "hardware/devices/cpu.h"
#include "hardware/devices/mlu.h"
#include "hardware/devices/nvidia.h"
#include "hardware/devices/mlu.h"

namespace refactor::hardware::device {

Expand Down
4 changes: 4 additions & 0 deletions src/04kernel/src/collectors/batch_normalization.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kernel/collectors/batch_normalization.h"
#include "../kernels/batch_normalization/cpu_kernel.hh"
#include "../kernels/batch_normalization/cudnn_kernel.hh"
#include "../kernels/batch_normalization/cnnl_kernel.hh"

namespace refactor::kernel {

Expand All @@ -20,6 +21,9 @@ namespace refactor::kernel {
case decltype(_target)::Nvidia:
REGISTER(BatchNormalizationCudnn)
break;
case decltype(_target)::Mlu:
REGISTER(BatchNormalizationCnnl)
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/cast.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kernel/collectors/cast.h"
#include "../kernels/cast/cpu_kernel.hh"
#include "../kernels/cast/cuda_kernel.hh"
#include "../kernels/cast/cnnl_kernel.hh"

namespace refactor::kernel {

Expand All @@ -24,6 +25,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = CastCnnl::build(from, to); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/clip.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kernel/collectors/clip.h"
#include "../kernels/clip/cpu_kernel.hh"
#include "../kernels/clip/cuda_kernel.hh"
#include "../kernels/clip/cnnl_kernel.hh"

namespace refactor::kernel {

Expand All @@ -24,6 +25,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = ClipCnnl::build(data, hasMax); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
8 changes: 8 additions & 0 deletions src/04kernel/src/collectors/concat.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "kernel/collectors/concat.h"
#include "../kernels/concat/cpu_kernel.hh"
#include "../kernels/concat/cuda_kernel.hh"
#include "../kernels/concat/cnnl_kernel.hh"

namespace refactor::kernel {

std::vector<KernelBox>
ConcatCollector::filter(TensorRefs inputs, TensorRefs outputs) const {
SplitInfo info(axis, inputs);

auto const &b = outputs[0];

std::vector<KernelBox> ans;
switch (_target) {
case decltype(_target)::Cpu:
Expand All @@ -20,6 +23,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = ConcatCnnl::build(axis, inputs, b); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/conv.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "kernel/collectors/conv.h"
#include "../kernels/conv/cnnl_kernel.hh"
#include "../kernels/conv/cudnn_kernel.hh"

namespace refactor::kernel {
Expand All @@ -23,6 +24,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = ConvCnnl::build(poolAttrs, x, w, b, y); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
13 changes: 12 additions & 1 deletion src/04kernel/src/collectors/gather.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "kernel/collectors/gather.h"
#include "../kernels/gather/cnnl_kernel.hh"
#include "../kernels/gather/cpu_kernel.hh"
#include "../kernels/gather/cuda_kernel.hh"

Expand All @@ -8,7 +9,12 @@ namespace refactor::kernel {
GatherCollector::filter(TensorRefs inputs, TensorRefs outputs) const {
GatherInfo info(axis, inputs[0], inputs[1]);

std::vector<KernelBox> ans;
auto const &a = inputs[0];
auto const &b = inputs[1];
auto const &c = outputs[0];

std::vector<KernelBox>
ans;
switch (_target) {
case decltype(_target)::Cpu:
if (auto ptr = GatherCpu::build(info); ptr != nullptr) {
Expand All @@ -20,6 +26,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = GatherCnnl::build(axis, a, b, c); ptr != nullptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/global_pool.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "kernel/collectors/global_pool.h"
#include "../kernels/pool/cudnn_kernel.hh"
#include "../kernels/pool/cnnl_kernel.hh"

namespace refactor::kernel {

Expand Down Expand Up @@ -28,6 +29,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = PoolCnnl::build(type, false, kernelShape, attributes, x, y); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/hard_sigmoid.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "kernel/collectors/hard_sigmoid.h"
#include "../kernels/hard_sigmoid/cnnl_kernel.hh"
#include "../kernels/hard_sigmoid/cpu_kernel.hh"
#include "../kernels/hard_sigmoid/cuda_kernel.hh"

Expand All @@ -20,6 +21,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = HardSigmoidCnnl::build(alpha, beta, a); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/mat_mul.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "kernel/collectors/mat_mul.h"
#include "../kernels/mat_mul/cnnl_kernel.hh"
#include "../kernels/mat_mul/cpu_kernel.hh"
#include "../kernels/mat_mul/cublas_kernel.hh"
#include "kernel/attributes/mat_mul_info.h"
Expand Down Expand Up @@ -26,6 +27,11 @@ namespace refactor::kernel {
case decltype(_target)::Nvidia:
REGISTER(MatMulCublas)
break;
case decltype(_target)::Mlu:
if (auto ptr = MatMulCnnl::build(inputs, outputs, transA, transB, alpha, beta); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
7 changes: 6 additions & 1 deletion src/04kernel/src/collectors/pad.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "kernel/collectors/pad.h"
#include "../kernels/pad/cnnl_kernel.hh"
#include "../kernels/pad/cpu_kernel.hh"
#include "../kernels/pad/cuda_kernel.hh"

Expand All @@ -22,11 +23,15 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = PadCnnl::build(dims, input.get().dataType, mode, const_value); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
return ans;
}

}// namespace refactor::kernel

6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/pool.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "kernel/collectors/pool.h"
#include "../kernels/pool/cudnn_kernel.hh"
#include "../kernels/pool/cnnl_kernel.hh"

namespace refactor::kernel {

Expand Down Expand Up @@ -29,6 +30,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = PoolCnnl::build(type, ceil, kernelShape, attributes, x, y); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
4 changes: 4 additions & 0 deletions src/04kernel/src/collectors/reduce.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kernel/collectors/reduce.h"
#include "../kernels/reduce/cpu_kernel.hh"
#include "../kernels/reduce/cudnn_kernel.hh"
#include "../kernels/reduce/cnnl_kernel.hh"

namespace refactor::kernel {

Expand All @@ -27,6 +28,9 @@ namespace refactor::kernel {
case decltype(_target)::Nvidia:
REGISTER(ReduceCudnn)
break;
case decltype(_target)::Mlu:
REGISTER(ReduceCnnl)
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/scatter_nd.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kernel/collectors/scatter_nd.h"
#include "../kernels/scatter_nd/cpu_kernel.hh"
#include "../kernels/scatter_nd/cuda_kernel.hh"
#include "../kernels/scatter_nd/cnnl_kernel.hh"

namespace refactor::kernel {

Expand All @@ -23,6 +24,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = ScatterNDCnnl::build(inputs, outputs); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
4 changes: 4 additions & 0 deletions src/04kernel/src/collectors/select.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kernel/collectors/select.h"
#include "../kernels/select/cpu_kernel.hh"
#include "../kernels/select/cuda_kernel.hh"
#include "../kernels/select/cnnl_kernel.hh"

namespace refactor::kernel {

Expand Down Expand Up @@ -35,6 +36,9 @@ namespace refactor::kernel {
case decltype(_target)::Nvidia:
REGISTER(SelectCuda)
break;
case decltype(_target)::Mlu:
REGISTER(SelectCnnl)
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
4 changes: 4 additions & 0 deletions src/04kernel/src/collectors/simple_binary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../kernels/simple_binary/binary_cudnn.hh"
#include "../kernels/simple_binary/cpu_kernel.hh"
#include "../kernels/simple_binary/cuda_kernel.hh"
#include "../kernels/simple_binary/binary_cnnl.hh"

namespace refactor::kernel {

Expand Down Expand Up @@ -50,6 +51,9 @@ namespace refactor::kernel {
REGISTER_BROCAST(BinaryCudnn)
REGISTER(BinaryCuda)
break;
case decltype(_target)::Mlu:
REGISTER_BROCAST(BinaryCnnl)
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/simple_unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "../kernels/simple_unary/cpu_kernel.hh"
#include "../kernels/simple_unary/cuda_kernel.hh"
#include "../kernels/simple_unary/cudnn_activation_kernel.hh"
#include "../kernels/simple_unary/cnnl_activation_kernel.hh"
#include "../kernels/simple_unary/cnnl_simple_unary_kernel.hh"
#include "common.h"

namespace refactor::kernel {
Expand Down Expand Up @@ -55,6 +57,10 @@ namespace refactor::kernel {
REGISTER(ActivationCudnn)
REGISTER(SimpleUnaryCuda)
break;
case decltype(_target)::Mlu:
REGISTER(ActivationCnnl)
REGISTER(SimpleUnaryCnnl)
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
6 changes: 6 additions & 0 deletions src/04kernel/src/collectors/slice.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kernel/collectors/slice.h"
#include "../kernels/slice/cpu_kernel.hh"
#include "../kernels/slice/cuda_kernel.hh"
#include "../kernels/slice/cnnl_kernel.hh"

namespace refactor::kernel {

Expand All @@ -26,6 +27,11 @@ namespace refactor::kernel {
ans.emplace_back(std::move(ptr));
}
break;
case decltype(_target)::Mlu:
if (auto ptr = SliceCnnl::build(inputs[0].get().dataType, dimentions, inputs[0].get().shape, outputs[0].get().shape); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
7 changes: 7 additions & 0 deletions src/04kernel/src/collectors/softmax.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "kernel/collectors/softmax.h"
#include "../kernels/softmax/cnnl_kernel.hh"
#include "../kernels/softmax/cpu_kernel.hh"
#include "../kernels/softmax/cuda_kernel.hh"
#include "../kernels/softmax/cudnn_kernel.hh"
Expand Down Expand Up @@ -28,6 +29,12 @@ namespace refactor::kernel {
}
break;
}
case decltype(_target)::Mlu: {
if (auto ptr = SoftmaxCnnl::build(cnnl::SoftmaxAlgo::ACCURATE, info); ptr) {
ans.emplace_back(std::move(ptr));
}
break;
}
default:
UNREACHABLEX(void, "Unknown target");
}
Expand Down
Loading
Loading