Skip to content

Commit

Permalink
Support RISC-V as an scalar MLAS target
Browse files Browse the repository at this point in the history
As a baseline patch, this preliminary RISC-V port leverages the
existing scalar implementation that was previously only utilized by
WASM target.

Also, we rename TARGET_WASM_SCALAR macros to TARGET_SCALAR, which
serves as a neutral designation that accommodates the inclusion
of RISC-V as a scalar target.

Reviewed-by: Alan Kao <[email protected]>
  • Loading branch information
CNOCycle committed Oct 26, 2023
1 parent 50c35c2 commit 6839b8d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
7 changes: 5 additions & 2 deletions onnxruntime/core/mlas/inc/mlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Module Name:
#if defined(MLAS_TARGET_ARM64) || defined(MLAS_TARGET_ARM64EC) || defined(MLAS_TARGET_ARM)
#define MLAS_TARGET_ARM_ANY
#endif
#if defined(__riscv__)
#define MLAS_TARGET_SCALAR
#endif

#if defined(__VSX__)
#define MLAS_TARGET_POWER
Expand All @@ -65,7 +68,7 @@ Module Name:
#if defined(__wasm_simd128__)
#define MLAS_TARGET_WASM_SIMD
#else
#define MLAS_TARGET_WASM_SCALAR
#define MLAS_TARGET_SCALAR
#endif
#endif

Expand Down Expand Up @@ -751,7 +754,7 @@ enum MLAS_CONV_ALGORITHM {
MlasConvAlgorithmGemmDirect,
MlasConvAlgorithmExpandThenGemm,
MlasConvAlgorithmExpandThenGemmSegmented,
#if defined(MLAS_TARGET_WASM_SCALAR)
#if defined(MLAS_TARGET_SCALAR)
MlasConvAlgorithmDepthwise,
#endif
};
Expand Down
8 changes: 4 additions & 4 deletions onnxruntime/core/mlas/lib/convolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ Return Value:
return;
}

#if defined(MLAS_TARGET_WASM_SCALAR)
#if defined(MLAS_TARGET_SCALAR)

if (Algorithm == MlasConvAlgorithmDepthwise) {
// Fill the Working Buffer with Zero for use by the depthwise kernel.
Expand Down Expand Up @@ -976,7 +976,7 @@ Return Value:
break;
}

#if defined(MLAS_TARGET_WASM_SCALAR)
#if defined(MLAS_TARGET_SCALAR)

case MlasConvAlgorithmDepthwise:
{
Expand Down Expand Up @@ -1224,7 +1224,7 @@ Return Value:

} else {

#if defined(MLAS_TARGET_WASM_SCALAR)
#if defined(MLAS_TARGET_SCALAR)

// Scalar direct conv for depthwise convolution.
// Currently only support 3x3 kernel with padding <=1 and dilations = 1.
Expand Down Expand Up @@ -1299,4 +1299,4 @@ Return Value:
}
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif
#endif
2 changes: 1 addition & 1 deletion onnxruntime/core/mlas/lib/mlasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ MlasFp32FromBits(
#pragma warning(pop)
#endif

#if defined(MLAS_TARGET_WASM_SCALAR)
#if defined(MLAS_TARGET_SCALAR)

void
MLASCALL
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/core/mlas/lib/sgemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Return Value:
}
}

#if !defined(MLAS_TARGET_WASM_SCALAR)
#if !defined(MLAS_TARGET_SCALAR)

void
MlasSgemmCopyPackB(
Expand Down Expand Up @@ -734,7 +734,7 @@ Return Value:
}
}

#else //defined(MLAS_TARGET_WASM_SCALAR)
#else //defined(MLAS_TARGET_SCALAR)

Check warning on line 737 in onnxruntime/core/mlas/lib/sgemm.cpp

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 At least two spaces is best between code and comments [whitespace/comments] [2] Raw Output: onnxruntime/core/mlas/lib/sgemm.cpp:737: At least two spaces is best between code and comments [whitespace/comments] [2]

Check warning on line 737 in onnxruntime/core/mlas/lib/sgemm.cpp

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Should have a space between // and comment [whitespace/comments] [4] Raw Output: onnxruntime/core/mlas/lib/sgemm.cpp:737: Should have a space between // and comment [whitespace/comments] [4]

void
MlasSgemmCopyPackB(
Expand Down

0 comments on commit 6839b8d

Please sign in to comment.