Skip to content

add RVV support for MPI_OP #13352

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions ompi/mca/op/riscv64/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# Copyright (c) 2019 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2025 Software System Team, SANECHIPS. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#

# This is an riscv64 op component. This Makefile.am is a typical
# riscv64 of how to integrate into Open MPI's Automake-based build
# system.
#
# See https://github.com/open-mpi/ompi/wiki/devel-CreateComponent
# for more details on how to make Open MPI components.

# First, list all .h and .c sources. It is necessary to list all .h
# files so that they will be picked up in the distribution tarball.

sources = \
op_riscv64.h \
op_riscv64_component.c

# Open MPI components can be compiled two ways:
#
# 1. As a standalone dynamic shared object (DSO), sometimes called a
# dynamically loadable library (DLL).
#
# 2. As a static library that is slurped up into the upper-level
# libmpi library (regardless of whether libmpi is a static or dynamic
# library). This is called a "Libtool convenience library".
#
# The component needs to create an output library in this top-level
# component directory, and named either mca_<type>_<name>.la (for DSO
# builds) or libmca_<type>_<name>.la (for static builds). The OMPI
# build system will have set the
# MCA_BUILD_ompi_<framework>_<component>_DSO AM_CONDITIONAL to indicate
# which way this component should be built.
specialized_op_libs =
if MCA_BUILD_ompi_op_has_rvv_support
specialized_op_libs += liblocal_ops_rvv.la
liblocal_ops_rvv_la_SOURCES = op_riscv64_functions.c
liblocal_ops_rvv_la_CPPFLAGS = -DGENERATE_RVV_CODE=1
endif

component_noinst = $(specialized_op_libs)
if MCA_BUILD_ompi_op_riscv64_DSO
component_install = mca_op_riscv64.la
else
component_install =
component_noinst += libmca_op_riscv64.la
endif

# Specific information for DSO builds.
#
# The DSO should install itself in $(ompilibdir) (by default,
# $prefix/lib/openmpi).

mcacomponentdir = $(ompilibdir)
mcacomponent_LTLIBRARIES = $(component_install)
mca_op_riscv64_la_SOURCES = $(sources)
mca_op_riscv64_la_LIBADD = $(specialized_op_libs)
mca_op_riscv64_la_LDFLAGS = -module -avoid-version $(top_builddir)/ompi/lib@[email protected]


# Specific information for static builds.
#
# Note that we *must* "noinst"; the upper-layer Makefile.am's will
# slurp in the resulting .la library into libmpi.

noinst_LTLIBRARIES = $(component_noinst)
libmca_op_riscv64_la_SOURCES = $(sources)
libmca_op_riscv64_la_LIBADD = $(specialized_op_libs)
libmca_op_riscv64_la_LDFLAGS = -module -avoid-version
64 changes: 64 additions & 0 deletions ompi/mca/op/riscv64/configure.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- shell-script -*-
#
# Copyright (c) 2019-2020 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2025 Software System Team, SANECHIPS. All rights reserved.
#
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#

# MCA_ompi_op_riscv_CONFIG([action-if-can-compile],
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_ompi_op_riscv64_CONFIG],[
AC_CONFIG_FILES([ompi/mca/op/riscv64/Makefile])
case "${host}" in
riscv64*)
op_riscv64_check="yes";;
*)
op_riscv64_check="no";;
esac
AS_IF([test "$op_riscv64_check" = "yes"],
[AC_LANG_PUSH([C])

#
# Check for RVV support
#
AC_CACHE_CHECK([for RVV support], op_cv_rvv_support,
[
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[
#if defined(__riscv) && defined(__riscv_v) && __riscv_xlen == 64
#include <riscv_vector.h>
#else
#error "Not a 64-bit RISC-V target"
#endif
]],
[[
#if defined(__riscv) && defined(__riscv_v) && __riscv_xlen == 64
size_t vl = __riscv_vsetvl_e32m1(4);
#endif
]])],
[op_cv_rvv_support=yes],
[op_cv_rvv_support=no])])
AC_LANG_POP
])
AM_CONDITIONAL([MCA_BUILD_ompi_op_has_rvv_support],
[test "$op_cv_rvv_support" = "yes"])

AC_SUBST(MCA_BUILD_ompi_op_has_rvv_support)

AS_IF([test "$op_cv_rvv_support" = "yes"],
[AC_DEFINE([OMPI_MCA_OP_HAVE_RVV], [1],[RVV supported in the current build])],
[AC_DEFINE([OMPI_MCA_OP_HAVE_RVV], [0],[RVV not supported in the current build])])

# If we have at least support for Neon or SVE
AS_IF([test "$op_cv_rvv_support" = "yes"],
[$1],
[$2])
])dnl
61 changes: 61 additions & 0 deletions ompi/mca/op/riscv64/op_riscv64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2019 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2025 Software System Team, SANECHIPS. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/

#ifndef MCA_OP_RISCV64_EXPORT_H
#define MCA_OP_RISCV64_EXPORT_H

#include "ompi_config.h"

#include "ompi/mca/mca.h"
#include "opal/class/opal_object.h"

#include "ompi/mca/op/op.h"

BEGIN_C_DECLS

/**
* Derive a struct from the base op component struct, allowing us to
* cache some component-specific information on our well-known
* component struct.
*/
typedef struct {
/** The base op component struct */
ompi_op_base_component_1_0_0_t super;

/* What follows is riscv64-component-specific cached information. We
tend to use this scheme (caching information on the riscv64
component itself) instead of lots of individual global
variables for the component. */

/** A simple boolean indicating that the hardware is available. */
bool hardware_available;

/** A simple boolean indicating whether double precision is
supported. */
bool double_supported;
} ompi_op_riscv64_component_t;

/**
* Globally exported variable. Note that it is a *riscv64* component
* (defined above), which has the ompi_op_base_component_t as its
* first member. Hence, the MCA/op framework will find the data that
* it expects in the first memory locations, but then the component
* itself can cache additional information after that that can be used
* by both the component and modules.
*/
OMPI_DECLSPEC extern ompi_op_riscv64_component_t
mca_op_riscv64_component;

END_C_DECLS

#endif /* MCA_OP_RISCV64_EXPORT_H */
Loading
Loading