Skip to content

Commit 0ca4183

Browse files
committed
add RVV support for MPI_OP
Signed-off-by: heyujiao99 <[email protected]>
1 parent a734508 commit 0ca4183

File tree

5 files changed

+887
-0
lines changed

5 files changed

+887
-0
lines changed

ompi/mca/op/riscv64/Makefile.am

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#
2+
# Copyright (c) 2019 The University of Tennessee and The University
3+
# of Tennessee Research Foundation. All rights
4+
# reserved.
5+
# Copyright (c) 2025 Software System Team, SANECHIPS. All rights reserved.
6+
# $COPYRIGHT$
7+
#
8+
# Additional copyrights may follow
9+
#
10+
# $HEADER$
11+
#
12+
13+
# This is an riscv64 op component. This Makefile.am is a typical
14+
# riscv64 of how to integrate into Open MPI's Automake-based build
15+
# system.
16+
#
17+
# See https://github.com/open-mpi/ompi/wiki/devel-CreateComponent
18+
# for more details on how to make Open MPI components.
19+
20+
# First, list all .h and .c sources. It is necessary to list all .h
21+
# files so that they will be picked up in the distribution tarball.
22+
23+
sources = \
24+
op_riscv64.h \
25+
op_riscv64_component.c
26+
27+
# Open MPI components can be compiled two ways:
28+
#
29+
# 1. As a standalone dynamic shared object (DSO), sometimes called a
30+
# dynamically loadable library (DLL).
31+
#
32+
# 2. As a static library that is slurped up into the upper-level
33+
# libmpi library (regardless of whether libmpi is a static or dynamic
34+
# library). This is called a "Libtool convenience library".
35+
#
36+
# The component needs to create an output library in this top-level
37+
# component directory, and named either mca_<type>_<name>.la (for DSO
38+
# builds) or libmca_<type>_<name>.la (for static builds). The OMPI
39+
# build system will have set the
40+
# MCA_BUILD_ompi_<framework>_<component>_DSO AM_CONDITIONAL to indicate
41+
# which way this component should be built.
42+
specialized_op_libs =
43+
if MCA_BUILD_ompi_op_has_rvv_support
44+
specialized_op_libs += liblocal_ops_rvv.la
45+
liblocal_ops_rvv_la_SOURCES = op_riscv64_functions.c
46+
liblocal_ops_rvv_la_CPPFLAGS = -DGENERATE_RVV_CODE=1
47+
endif
48+
49+
component_noinst = $(specialized_op_libs)
50+
if MCA_BUILD_ompi_op_riscv64_DSO
51+
component_install = mca_op_riscv64.la
52+
else
53+
component_install =
54+
component_noinst += libmca_op_riscv64.la
55+
endif
56+
57+
# Specific information for DSO builds.
58+
#
59+
# The DSO should install itself in $(ompilibdir) (by default,
60+
# $prefix/lib/openmpi).
61+
62+
mcacomponentdir = $(ompilibdir)
63+
mcacomponent_LTLIBRARIES = $(component_install)
64+
mca_op_riscv64_la_SOURCES = $(sources)
65+
mca_op_riscv64_la_LIBADD = $(specialized_op_libs)
66+
mca_op_riscv64_la_LDFLAGS = -module -avoid-version $(top_builddir)/ompi/lib@[email protected]
67+
68+
69+
# Specific information for static builds.
70+
#
71+
# Note that we *must* "noinst"; the upper-layer Makefile.am's will
72+
# slurp in the resulting .la library into libmpi.
73+
74+
noinst_LTLIBRARIES = $(component_noinst)
75+
libmca_op_riscv64_la_SOURCES = $(sources)
76+
libmca_op_riscv64_la_LIBADD = $(specialized_op_libs)
77+
libmca_op_riscv64_la_LDFLAGS = -module -avoid-version

ompi/mca/op/riscv64/configure.m4

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -*- shell-script -*-
2+
#
3+
# Copyright (c) 2019-2020 The University of Tennessee and The University
4+
# of Tennessee Research Foundation. All rights
5+
# reserved.
6+
# Copyright (c) 2025 Software System Team, SANECHIPS. All rights reserved.
7+
#
8+
# $COPYRIGHT$
9+
#
10+
# Additional copyrights may follow
11+
#
12+
# $HEADER$
13+
#
14+
15+
# MCA_ompi_op_riscv_CONFIG([action-if-can-compile],
16+
# [action-if-cant-compile])
17+
# ------------------------------------------------
18+
AC_DEFUN([MCA_ompi_op_riscv64_CONFIG],[
19+
AC_CONFIG_FILES([ompi/mca/op/riscv64/Makefile])
20+
case "${host}" in
21+
riscv64*)
22+
op_riscv64_check="yes";;
23+
*)
24+
op_riscv64_check="no";;
25+
esac
26+
AS_IF([test "$op_riscv64_check" = "yes"],
27+
[AC_LANG_PUSH([C])
28+
29+
#
30+
# Check for RVV support
31+
#
32+
AC_CACHE_CHECK([for RVV support], op_cv_rvv_support,
33+
[
34+
AC_LINK_IFELSE(
35+
[AC_LANG_PROGRAM([[
36+
#if defined(__riscv) && defined(__riscv_v) && __riscv_xlen == 64
37+
#include <riscv_vector.h>
38+
#else
39+
#error "Not a 64-bit RISC-V target"
40+
#endif
41+
]],
42+
[[
43+
#if defined(__riscv) && defined(__riscv_v) && __riscv_xlen == 64
44+
size_t vl = __riscv_vsetvl_e32m1(4);
45+
#endif
46+
]])],
47+
[op_cv_rvv_support=yes],
48+
[op_cv_rvv_support=no])])
49+
AC_LANG_POP
50+
])
51+
AM_CONDITIONAL([MCA_BUILD_ompi_op_has_rvv_support],
52+
[test "$op_cv_rvv_support" = "yes"])
53+
54+
AC_SUBST(MCA_BUILD_ompi_op_has_rvv_support)
55+
56+
AS_IF([test "$op_cv_rvv_support" = "yes"],
57+
[AC_DEFINE([OMPI_MCA_OP_HAVE_RVV], [1],[RVV supported in the current build])],
58+
[AC_DEFINE([OMPI_MCA_OP_HAVE_RVV], [0],[RVV not supported in the current build])])
59+
60+
# If we have at least support for Neon or SVE
61+
AS_IF([test "$op_cv_rvv_support" = "yes"],
62+
[$1],
63+
[$2])
64+
])dnl

ompi/mca/op/riscv64/op_riscv64.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2019 The University of Tennessee and The University
3+
* of Tennessee Research Foundation. All rights
4+
* reserved.
5+
* Copyright (c) 2025 Software System Team, SANECHIPS. All rights reserved.
6+
*
7+
* $COPYRIGHT$
8+
*
9+
* Additional copyrights may follow
10+
*
11+
* $HEADER$
12+
*/
13+
14+
#ifndef MCA_OP_RISCV64_EXPORT_H
15+
#define MCA_OP_RISCV64_EXPORT_H
16+
17+
#include "ompi_config.h"
18+
19+
#include "ompi/mca/mca.h"
20+
#include "opal/class/opal_object.h"
21+
22+
#include "ompi/mca/op/op.h"
23+
24+
BEGIN_C_DECLS
25+
26+
/**
27+
* Derive a struct from the base op component struct, allowing us to
28+
* cache some component-specific information on our well-known
29+
* component struct.
30+
*/
31+
typedef struct {
32+
/** The base op component struct */
33+
ompi_op_base_component_1_0_0_t super;
34+
35+
/* What follows is riscv64-component-specific cached information. We
36+
tend to use this scheme (caching information on the riscv64
37+
component itself) instead of lots of individual global
38+
variables for the component. */
39+
40+
/** A simple boolean indicating that the hardware is available. */
41+
bool hardware_available;
42+
43+
/** A simple boolean indicating whether double precision is
44+
supported. */
45+
bool double_supported;
46+
} ompi_op_riscv64_component_t;
47+
48+
/**
49+
* Globally exported variable. Note that it is a *riscv64* component
50+
* (defined above), which has the ompi_op_base_component_t as its
51+
* first member. Hence, the MCA/op framework will find the data that
52+
* it expects in the first memory locations, but then the component
53+
* itself can cache additional information after that that can be used
54+
* by both the component and modules.
55+
*/
56+
OMPI_DECLSPEC extern ompi_op_riscv64_component_t
57+
mca_op_riscv64_component;
58+
59+
END_C_DECLS
60+
61+
#endif /* MCA_OP_RISCV64_EXPORT_H */

0 commit comments

Comments
 (0)