Skip to content

Commit ff5ddda

Browse files
committed
Add init impl for riscv64 matmul.
1 parent d0bab63 commit ff5ddda

File tree

7 files changed

+230
-157
lines changed

7 files changed

+230
-157
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ option(BUILD_BENCHMARK "Build benchmark programs" ON)
5151
option(BUILD_TESTING "Build test programs" OFF)
5252
option(ENABLE_OP_PROFILE "Profile ops cast time" OFF)
5353
option(ENABLE_DUMP_MANAGER "Enable dump manager" OFF)
54-
option(ENABLE_RVV "Some kernel impl by rvv" OFF)
5554
option(ENABLE_DUMP_MEM "Dump mem usage" OFF)
5655

5756
if (BUILDING_RUNTIME)

src/Native/src/kernels/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
set(SRCS kernel_context.cpp)
44

55
if (BUILDING_RUNTIME)
6-
# used for rvv
7-
if(ENABLE_RVV)
8-
add_definitions(-D__riscv_vector=1)
9-
add_compile_options(-march=rv64imafdcv)
10-
endif()
11-
126
add_library(kernels OBJECT ${SRCS})
137
target_include_directories(kernels PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
148
target_link_libraries(kernels PUBLIC gsl::gsl-lite)
@@ -25,9 +19,9 @@ else()
2519
# if(os_name STREQUAL "linux")
2620
# target_link_libraries(kernels PRIVATE -lpthread)
2721
# endif()
28-
# target_compile_definitions(kernels PRIVATE "-DNNCASE_HALIDE")
22+
# target_compile_definitions(kernels PRIVATE "-DNNCASE_HALIDE")
2923
# endif()
30-
24+
3125
target_compile_definitions(kernels PUBLIC -DNNCASE_DLL -DNNCASE_SIMULATOR)
3226
set_property(TARGET kernels PROPERTY POSITION_INDEPENDENT_CODE ON)
3327
endif()

src/Native/src/kernels/stackvm/optimized/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ _TARGET_ARCH_FILES(TARGET kernels
4545
FILES
4646
binary.cpp
4747
layer_norm.cpp
48-
#matmul.cpp
48+
matmul.cpp
4949
sigmoid.cpp
5050
softmax.cpp
5151
unary.cpp
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Copyright 2019-2021 Canaan Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
#include "../reference/ref_ops.h"
16+
#include "opt_ops.h"
17+
#include <iostream>
18+
#include <nncase/kernels/kernel_utils.h>
19+
#include <nncase/runtime/runtime_op_utility.h>
20+
21+
using namespace nncase;
22+
using namespace nncase::runtime;
23+
using namespace nncase::kernels;
24+
using namespace nncase::kernels::stackvm;
25+
using namespace nncase::kernels::stackvm::optimized;
26+
27+
result<void> optimized::matmul(typecode_t typecode, const gsl::byte *input_a, const gsl::byte *input_b,
28+
gsl::byte *output,
29+
gsl::span<const size_t> in_a_shape,
30+
gsl::span<const size_t> in_b_shape,
31+
[[maybe_unused]] kernel_context &context) noexcept {
32+
return stackvm::reference::matmul(typecode, input_a, input_b, output, in_a_shape, in_b_shape, context);
33+
}

src/Native/src/kernels/stackvm/optimized/opt_ops.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,11 @@ unary(typecode_t dtype, runtime::stackvm::unary_op_t op, const gsl::byte *in,
139139
gsl::span<const size_t> out_strides,
140140
kernel_context &context = default_kernel_context()) noexcept;
141141

142-
// template <typename T>
143-
// NNCASE_API result<void> matmul(const T *input_a, const T *input_b, const T
144-
// *bias, T *output,
145-
// gsl::span<const size_t> in_a_shape, const
146-
// dims_t &in_a_strides, gsl::span<const size_t>
147-
// in_b_shape, const dims_t &in_b_strides,
148-
// gsl::span<const size_t> out_shape,
149-
// gsl::span<const size_t> out_strides,
150-
// value_range<float> fused_activation) noexcept;
142+
NNCASE_API result<void>
143+
matmul(typecode_t typecode, const gsl::byte *input_a, const gsl::byte *input_b,
144+
gsl::byte *output, gsl::span<const size_t> in_a_shape,
145+
gsl::span<const size_t> in_b_shape,
146+
[[maybe_unused]] kernel_context &context) noexcept;
151147

152148
// template <typename T>
153149
NNCASE_API result<void>

0 commit comments

Comments
 (0)