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

Add RISC-V and RVV1.0 support into library #1

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dadceeb
feat: add CMake options for RISC-V and RVV1.0
suvorovrain Nov 29, 2024
2cf8670
feat: add riscv vectorization support in global values
suvorovrain Nov 29, 2024
5e6d5f9
feat: add defines for RVV1.0
suvorovrain Nov 29, 2024
3eb13f9
feat: add rvv function templates
suvorovrain Nov 29, 2024
78957e3
test: add test
suvorovrain Nov 30, 2024
cc334ff
fix: add defines for RVV implementation
suvorovrain Nov 30, 2024
4b4329d
feat: implement vectorized with rvv saxpy function
suvorovrain Dec 14, 2024
31a7ed7
feat: correct include
suvorovrain Dec 14, 2024
80fd86a
feat: correct support of saxpy5 lv in factory kernels.
suvorovrain Dec 18, 2024
00fad56
fix: correct vector extension define in global structure
suvorovrain Dec 18, 2024
85217a4
fix: saxpy function with rvv
suvorovrain Dec 18, 2024
e6070fe
refactor: remove straided functions
suvorovrain Dec 27, 2024
65936ea
fix: redundant arguments
suvorovrain Dec 30, 2024
c57ccb2
refactor: remove test files
suvorovrain Jan 2, 2025
bee2b98
refactor: remove debug prints
suvorovrain Jan 2, 2025
14d84da
fix: codegen rvv support
suvorovrain Jan 2, 2025
4e5d24b
small refactor
suvorovrain Jan 2, 2025
686f76a
refactor: jit kernel rvv support
suvorovrain Jan 2, 2025
13ff474
refactor: new line symbol
suvorovrain Jan 2, 2025
c8e0894
refactor: very small
suvorovrain Jan 4, 2025
72564cf
feat: implement float support
suvorovrain Feb 5, 2025
9d566fe
feat: implement riscv support in cpufeatures
suvorovrain Feb 8, 2025
7c575d2
Merge pull request #2 from suvorovrain/riscvcpufeat
suvorovrain Feb 8, 2025
40a9aa5
refactor: add new line symbol
suvorovrain Feb 9, 2025
0c67d9a
fix: update target
suvorovrain Feb 10, 2025
1894cb0
fix: new line characters
suvorovrain Feb 10, 2025
d856df9
refactor: rename global rvv var
suvorovrain Feb 10, 2025
239a243
Merge pull request #3 from suvorovrain/rvvtest
suvorovrain Feb 10, 2025
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
20 changes: 20 additions & 0 deletions GraphBLAS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ if ( DEFINED GBAVX512F )
endif ( )
endif ( )

#-------------------------------------------------------------------------------
# RISC-V
#-------------------------------------------------------------------------------

if ( DEFINED GBRISCV64 )
if ( GBRISCV64 )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBRISCV64=1 " )
else ( )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBRISCV64=0 " )
endif ( )
endif ( )

if ( DEFINED GBRVV )
if ( GBRVV )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBRVV=1 " )
else ( )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBRVV=0 " )
endif ( )
endif ( )

#-------------------------------------------------------------------------------
# check compiler features
#-------------------------------------------------------------------------------
Expand Down
33 changes: 33 additions & 0 deletions GraphBLAS/FactoryKernels/GB_AxB__plus_times_fp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@

//------------------------------------------------------------------------------

#ifdef GBRISCV64
#include <riscv_vector.h>
#endif
#include "GB.h"
#include "GB_control.h"
#include "mxm/GB_AxB_saxpy.h"
#include "include/GB_unused.h"
#include "assign/GB_bitmap_assign_methods.h"
#include "FactoryKernels/GB_AxB__include2.h"

// riscv intrinsics

#define VSETVL(x) __riscv_vsetvl_e32m8(x)
#define VLE(x,y) __riscv_vle32_v_f32m8(x, y)
#define VFMACC(x,y,z,w) __riscv_vfmacc_vf_f32m8(x, y, z, w)
#define VSE(x,y,z) __riscv_vse32_v_f32m8(x, y, z)
#define VECTORTYPE vfloat32m8_t

// semiring operators:
#define GB_MULTADD(z,a,b,i,k,j) z += (a*b)
#define GB_MULT(z,a,b,i,k,j) z = (a*b)
Expand Down Expand Up @@ -43,6 +54,7 @@
// special case semirings:

#define GB_SEMIRING_HAS_AVX_IMPLEMENTATION 1
#define GB_SEMIRING_HAS_RVV_IMPLEMENTATION 1

// monoid properties:
#define GB_Z_TYPE float
Expand Down Expand Up @@ -282,6 +294,27 @@ GrB_Info GB (_Asaxpy4B__plus_times_fp32)

#endif

//----------------------------------------------------------------------
// saxpy5 method with RISC-V vectors
//---------------------------------------------------------------------

#if GB_COMPILER_SUPPORTS_RVV1

GB_TARGET_RVV1 static inline void GB_AxB_saxpy5_unrolled_rvv
(
GrB_Matrix C,
const GrB_Matrix A,
const GrB_Matrix B,
const int ntasks,
const int nthreads,
const int64_t *B_slice
)
{
#include "mxm/template/GB_AxB_saxpy5_lv.c"
}

#endif

//----------------------------------------------------------------------
// saxpy5 method unrolled, with no vectors
//----------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions GraphBLAS/FactoryKernels/GB_AxB__plus_times_fp64.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@

//------------------------------------------------------------------------------

#ifdef GBRISCV64
#include <riscv_vector.h>
#endif
#include "GB.h"
#include "GB_control.h"
#include "mxm/GB_AxB_saxpy.h"
#include "include/GB_unused.h"
#include "assign/GB_bitmap_assign_methods.h"
#include "FactoryKernels/GB_AxB__include2.h"

// riscv intrinsics

#define VSETVL(x) __riscv_vsetvl_e64m8(x)
#define VLE(x,y) __riscv_vle64_v_f64m8(x, y)
#define VFMACC(x,y,z,w) __riscv_vfmacc_vf_f64m8(x, y, z, w)
#define VSE(x,y,z) __riscv_vse64_v_f64m8(x, y, z)
#define VECTORTYPE vfloat64m8_t

// semiring operators:
#define GB_MULTADD(z,a,b,i,k,j) z += (a*b)
#define GB_MULT(z,a,b,i,k,j) z = (a*b)
Expand Down Expand Up @@ -43,6 +54,7 @@
// special case semirings:

#define GB_SEMIRING_HAS_AVX_IMPLEMENTATION 1
#define GB_SEMIRING_HAS_RVV_IMPLEMENTATION 1

// monoid properties:
#define GB_Z_TYPE double
Expand Down Expand Up @@ -282,6 +294,26 @@ GrB_Info GB (_Asaxpy4B__plus_times_fp64)

#endif

//----------------------------------------------------------------------
// saxpy5 method with RISC-V vectors
//----------------------------------------------------------------------
#if GB_COMPILER_SUPPORTS_RVV1

GB_TARGET_RVV1 static inline void GB_AxB_saxpy5_unrolled_rvv
(
GrB_Matrix C,
const GrB_Matrix A,
const GrB_Matrix B,
const int ntasks,
const int nthreads,
const int64_t *B_slice
)
{
#include "mxm/template/GB_AxB_saxpy5_lv.c"
}

#endif

//----------------------------------------------------------------------
// saxpy5 method unrolled, with no vectors
//----------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions GraphBLAS/GraphBLAS/rename/GB_rename.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@
#define GB_Global_calloc_function_set GM_Global_calloc_function_set
#define GB_Global_cpu_features_avx2 GM_Global_cpu_features_avx2
#define GB_Global_cpu_features_avx512f GM_Global_cpu_features_avx512f
#define GB_Global_cpu_features_rvv GM_Global_cpu_features_rvv
#define GB_Global_cpu_features_query GM_Global_cpu_features_query
#define GB_Global_flush_get GM_Global_flush_get
#define GB_Global_flush_set GM_Global_flush_set
Expand Down
25 changes: 25 additions & 0 deletions GraphBLAS/Source/codegen/Generator/GB_AxB.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

//------------------------------------------------------------------------------

#ifdef GBRISCV64
#include <riscv_vector.h>
#endif
#include "GB.h"
#include "GB_control.h"
#include "mxm/GB_AxB_saxpy.h"
Expand Down Expand Up @@ -310,6 +313,28 @@ m4_divert(if_semiring_has_avx)
}

#endif
m4_divert(if_semiring_has_rvv)
//----------------------------------------------------------------------
// saxpy5 method with RISC-V vectors
//----------------------------------------------------------------------

#if GB_COMPILER_SUPPORTS_RVV1

GB_TARGET_RVV1 static inline void GB_AxB_saxpy5_unrolled_rvv
(
GrB_Matrix C,
const GrB_Matrix A,
const GrB_Matrix B,
const int ntasks,
const int nthreads,
const int64_t *B_slice
)
{
#include "mxm/template/GB_AxB_saxpy5_lv.c"
}

#endif

m4_divert(if_saxpy5_enabled)

//----------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions GraphBLAS/Source/cpu/GB_cpu_features_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "src/impl_x86_freebsd.c"
#include "src/impl_x86_linux_or_android.c"
#include "src/impl_x86_windows.c"
#include "src/impl_riscv_linux.c"
#if GBX86
#if (defined(__apple__) || defined(__APPLE__) || defined(__MACH__))
// needed for src/impl_x86_macos.c:
Expand Down
29 changes: 28 additions & 1 deletion GraphBLAS/Source/global/GB_Global.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ typedef struct

bool cpu_features_avx2 ; // x86_64 with AVX2
bool cpu_features_avx512f ; // x86_64 with AVX512f
bool cpu_features_rvv ; // RISC-V with RVV1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be cpu_features_rvv_1_0 or something else to note that it may be incompatible with 0.7 ?


//--------------------------------------------------------------------------
// CUDA (DRAFT: in progress):
Expand Down Expand Up @@ -215,6 +216,7 @@ static GB_Global_struct GB_Global =
// CPU features
.cpu_features_avx2 = false, // x86_64 with AVX2
.cpu_features_avx512f = false, // x86_64 with AVX512f
.cpu_features_rvv = false, // RISC-V with RVV1.0

// CUDA environment (DRAFT: in progress)
.gpu_count = 0, // # of GPUs in the system
Expand Down Expand Up @@ -306,16 +308,36 @@ void GB_Global_cpu_features_query (void)
}
#endif

}
#elif GBRISCV64
{
//----------------------------------------------------------------------
// xRISC-V architecture: see if RVV1.0 is supported
//----------------------------------------------------------------------

#if defined ( GBRVV )
{
// the build system asserts whether or not RVV1.0 is available
GB_Global.cpu_features_rvv = (bool) (GBRVV) ;
}
#else
{
// RVV1.0 not available
GB_Global.cpu_features_rvv = false ;
}
#endif

}
#else
{

//----------------------------------------------------------------------
// not on the x86_64 architecture, so no AVX2 or AVX512F acceleration
// not on the x86_64 or RISC-V architecture, so no AVX2, AVX512F or RVV1.0 acceleration
//----------------------------------------------------------------------

GB_Global.cpu_features_avx2 = false ;
GB_Global.cpu_features_avx512f = false ;
GB_Global.cpu_features_rvv = false ;

}
#endif
Expand All @@ -331,6 +353,11 @@ bool GB_Global_cpu_features_avx512f (void)
return (GB_Global.cpu_features_avx512f) ;
}

bool GB_Global_cpu_features_rvv (void)
{
return (GB_Global.cpu_features_rvv) ;
}

//------------------------------------------------------------------------------
// hyper_switch
//------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions GraphBLAS/Source/global/GB_Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
void GB_Global_cpu_features_query (void) ;
bool GB_Global_cpu_features_avx2 (void) ;
bool GB_Global_cpu_features_avx512f (void) ;
bool GB_Global_cpu_features_rvv (void) ;

void GB_Global_mode_set (GrB_Mode mode) ;
GrB_Mode GB_Global_mode_get (void) ;
Expand Down
35 changes: 35 additions & 0 deletions GraphBLAS/Source/include/GB_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@

#endif

#if !defined ( GBRISCV64 )

#if defined(__riscv)
#define GBRISCV64 1
#else
#define GBRISCV64 0
#endif

#endif

//------------------------------------------------------------------------------
// AVX2 and AVX512F support for the x86_64 architecture
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -306,6 +316,31 @@
#define GB_TARGET_AVX2
#endif

//------------------------------------------------------------------------------
// RVV1.0 support for the RISC-V architecture
//------------------------------------------------------------------------------

#if GBRISCV64
#if GB_COMPILER_GCC
// TODO: add other compilers
#if __GNUC__ >= 13
#define GB_COMPILER_SUPPORTS_RVV1 1
#else
#define GB_COMPILER_SUPPORTS_RVV1 0
#endif
#endif
#else
// non-RISC-V architecture
#define GB_COMPILER_SUPPORTS_RVV1 0
#endif

// prefix for function with target rvv1.0
#if GB_COMPILER_SUPPORTS_RVV1
#define GB_TARGET_RVV1 __attribute__ ((target ("arch=rv64gcv")))
#else
#define GB_TARGET_RVV1
#endif

//------------------------------------------------------------------------------
// disable Google's cpu_featgures on some compilers
//------------------------------------------------------------------------------
Expand Down
38 changes: 38 additions & 0 deletions GraphBLAS/Source/jit_kernels/template/GB_jit_kernel_AxB_saxpy5.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
//------------------------------------------------------------------------------

#include "include/GB_AxB_saxpy3_template.h"
#ifdef GBRISCV64
#include <riscv_vector.h>
#endif

GB_JIT_GLOBAL GB_JIT_KERNEL_AXB_SAXPY5_PROTO (GB_jit_kernel) ;

Expand Down Expand Up @@ -82,6 +85,27 @@ GB_JIT_GLOBAL GB_JIT_KERNEL_AXB_SAXPY5_PROTO (GB_jit_kernel) ;
}

#endif

//----------------------------------------------------------------------
// saxpy5 method with RISC-V vectors
//----------------------------------------------------------------------

#if GB_COMPILER_SUPPORTS_RVV1

GB_TARGET_AVX2 static inline void GB_AxB_saxpy5_unrolled_rvv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is GB_TARGET_AVX2 the correct macro?

(
GrB_Matrix C,
const GrB_Matrix A,
const GrB_Matrix B,
const int ntasks,
const int nthreads,
const int64_t *B_slice
)
{
#include "template/GB_AxB_saxpy5_lv.c"
}

#endif

#endif

Expand Down Expand Up @@ -171,6 +195,20 @@ GB_JIT_GLOBAL GB_JIT_KERNEL_AXB_SAXPY5_PROTO (GB_jit_kernel)
}
#endif

#if GB_SEMIRING_HAS_RVV_IMPLEMENTATION
{
#if GB_COMPILER_SUPPORTS_RVV1
if (cpu_has_avx2)
{
// RISC-V64 with RVV1.0
GB_AxB_saxpy5_unrolled_rvv (C, A, B, ntasks, nthreads,
B_slice) ;
return (GrB_SUCCESS) ;
}
#endif
}
#endif

// any architecture and any semiring
GB_AxB_saxpy5_unrolled_vanilla (C, A, B, ntasks, nthreads, B_slice) ;

Expand Down
Loading
Loading