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

Adding OpGen backend to develop #330

Open
wants to merge 2 commits into
base: develop
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
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ project( GraphBLAS
DESCRIPTION "The ultimate engine for sparse computation"
LANGUAGES CXX C
)
set( CMAKE_CXX_STANDARD 11 )
set( CMAKE_CXX_STANDARD 14 )
Copy link
Member

Choose a reason for hiding this comment

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

Why was this bump (C++11 to C++14) needed actually @aristeidis-mastoras ?

set( CMAKE_CXX_STANDARD_REQUIRED ON )

# install within the build directory by default (NOT to /usr/local or the likes)
Expand All @@ -52,13 +52,14 @@ endif()
option( WITH_REFERENCE_BACKEND "With Reference backend" ON )
option( WITH_OMP_BACKEND "With OMP backend" ON )
option( WITH_HYPERDAGS_BACKEND "With Hyperdags backend" ON )
option( WITH_ASCEND_BACKEND "With Ascend backend" ON )
if( WITH_HYPERDAGS_BACKEND )
if( NOT DEFINED WITH_HYPERDAGS_USING )
set( WITH_HYPERDAGS_USING "reference" )
endif()
endif()
option( WITH_NONBLOCKING_BACKEND "With Nonblocking backend" ON )
option( WITH_NUMA "With NUMA support" ON )
option( WITH_NUMA "With NUMA support" OFF )
option( LPF_INSTALL_PATH "Path to the LPF tools for the BSP1D and Hybrid backends" OFF )
# the following options depend on LPF_INSTALL_PATH being set
include(CMakeDependentOption)
Expand Down Expand Up @@ -192,6 +193,12 @@ if( WITH_HYBRID_BACKEND )
endif()
endif()

# Enable nonblocking backend if ascend is active
if( WITH_ASCEND_BACKEND )
set( WITH_NONBLOCKING_BACKEND ON )
message( STATUS "Enabling compilation of nonblocking backend: required by the Ascend backend" )
endif()

# Enabling reference_omp backend if non-blocking is active
if( WITH_NONBLOCKING_BACKEND )
if( NOT WITH_OMP_BACKEND )
Expand Down
10 changes: 9 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ the location where LPF is installed"
echo " optional; default value is reference"
echo " clashes with --no-hyperdags"
echo " --no-nonblocking - disables the nonblocking backend"
echo " --no-ascend - disables the ascend backend"
echo " --[debug | coverage]-build - build the project with debug | coverage options (tests will run much slower!)"
echo " --generator=<value> - set the generator for CMake (otherwise use CMake's default)"
echo " --show - show generation commands instead of running them"
Expand All @@ -102,6 +103,7 @@ reference=yes
hyperdags=yes
hyperdags_using=reference
nonblocking=yes
ascend=yes
banshee=no
lpf=no
show=no
Expand Down Expand Up @@ -176,6 +178,9 @@ or assume default paths (--with-lpf)"
--no-nonblocking)
nonblocking=no
;;
--no-ascend)
ascend=no
;;
--debug-build)
debug_build=yes
;;
Expand Down Expand Up @@ -286,7 +291,7 @@ CURRENT_DIR="$(pwd)"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

# CONFIGURE CMAKE BUILDING INFRASTRUCTURE
if [[ "${reference}" == "yes" || "${lpf}" == "yes" || "${nonblocking}" == "yes" ]]; then
if [[ "${reference}" == "yes" || "${lpf}" == "yes" || "${nonblocking}" == "yes" || "${ascend}" == "yes" ]]; then
BUILD_DIR="${CURRENT_DIR}"

printf "Checking for cmake..."
Expand Down Expand Up @@ -363,6 +368,9 @@ the current directory before invocation or confirm the deletion of its content w
if [[ "${nonblocking}" == "no" ]]; then
CMAKE_OPTS+=" -DWITH_NONBLOCKING_BACKEND=OFF"
fi
if [[ "${ascend}" == "no" ]]; then
CMAKE_OPTS+=" -DWITH_ASCEND_BACKEND=OFF"
fi
if [[ "${lpf}" == "yes" ]]; then
CMAKE_OPTS+=" -DLPF_INSTALL_PATH='${ABSOLUTE_LPF_INSTALL_PATH}'"
fi
Expand Down
10 changes: 9 additions & 1 deletion cmake/AddGRBInstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ set( SHMEM_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/sequential" )
set( HYPERDAGS_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hyperdags" )
set( BSP1D_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/spmd" )
set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" )

set( ASCEND_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/ascend" )


# addBackendWrapperGenOptions
Expand Down Expand Up @@ -146,6 +146,14 @@ if( WITH_NONBLOCKING_BACKEND )
)
endif()

if( WITH_ASCEND_BACKEND )
addBackendWrapperGenOptions( "ascend"
COMPILE_DEFINITIONS "${ASCEND_SELECTION_DEFS};${ASCEND_INCLUDE_DEFS}"
LINK_FLAGS "'${SHMEM_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'"
"'${ALP_UTILS_INSTALL_DIR}/lib${ALP_UTILS_LIBRARY_OUTPUT_NAME}.a'" "${NUMA_LFLAG}"
)
endif()

# distributed memory backends
if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND )
assert_valid_variables( LPFRUN LPFCPP )
Expand Down
9 changes: 8 additions & 1 deletion cmake/AddGRBVars.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set( BSP1D_BACKEND_DEFAULT_NAME "backend_bsp1d" )
set( HYBRID_BACKEND_DEFAULT_NAME "backend_hybrid" )
set( HYPERDAGS_BACKEND_DEFAULT_NAME "backend_hyperdags" )
set( NONBLOCKING_BACKEND_DEFAULT_NAME "backend_nonblocking" )
set( ASCEND_BACKEND_DEFAULT_NAME "backend_ascend" )

### COMPILER DEFINITIONS FOR HEADERS INCLUSION AND FOR BACKEND SELECTION

Expand All @@ -41,6 +42,7 @@ set( REFERENCE_INCLUDE_DEFS "_GRB_WITH_REFERENCE" )
set( REFERENCE_OMP_INCLUDE_DEFS "_GRB_WITH_OMP" )
set( HYPERDAGS_INCLUDE_DEFS "_GRB_WITH_HYPERDAGS" )
set( NONBLOCKING_INCLUDE_DEFS "_GRB_WITH_NONBLOCKING" )
set( ASCEND_INCLUDE_DEFS "_GRB_WITH_ASCEND" )
set( LPF_INCLUDE_DEFS "_GRB_WITH_LPF" )

# compiler definitions to select a backend
Expand All @@ -51,6 +53,7 @@ set( HYPERDAGS_SELECTION_DEFS
"_GRB_WITH_HYPERDAGS_USING=${WITH_HYPERDAGS_USING}"
)
set( NONBLOCKING_SELECTION_DEFS "_GRB_BACKEND=nonblocking" )
set( ASCEND_SELECTION_DEFS "_GRB_BACKEND=ascend" )
set( BSP1D_SELECTION_DEFS
"_GRB_BACKEND=BSP1D"
"_GRB_BSP1D_BACKEND=reference"
Expand All @@ -64,7 +67,7 @@ set( HYBRID_SELECTION_DEFS
set( NO_NUMA_DEF "_GRB_NO_LIBNUMA" )

### **ALL** BACKENDS, EVEN IF NOT ENABLED BY USER
set( ALL_BACKENDS "reference" "reference_omp" "hyperdags" "nonblocking" "bsp1d" "hybrid" )
set( ALL_BACKENDS "reference" "reference_omp" "hyperdags" "nonblocking" "ascend" "bsp1d" "hybrid" )

# list of user-enabled backends, for tests and wrapper scripts (do not change!)
set( AVAILABLE_BACKENDS "" )
Expand All @@ -90,6 +93,10 @@ if( WITH_NONBLOCKING_BACKEND )
list( APPEND AVAILABLE_BACKENDS "nonblocking" )
endif()

if( WITH_ASCEND_BACKEND )
list( APPEND AVAILABLE_BACKENDS "ascend" )
endif()

# distributed memory backends
if( WITH_BSP1D_BACKEND )
list( APPEND AVAILABLE_BACKENDS "bsp1d" )
Expand Down
2 changes: 1 addition & 1 deletion docs/Build_and_test_infra.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ build path, with
set_target_properties( backend_example_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/example_output_dir" )
```

1. add the new library to the `libs` target, which allows users to compile all
7. add the new library to the `libs` target, which allows users to compile all
backend libraries at once

```cmake
Expand Down
56 changes: 55 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#

assert_defined_variables( WITH_REFERENCE_BACKEND WITH_OMP_BACKEND )
assert_defined_variables( WITH_REFERENCE_BACKEND WITH_OMP_BACKEND WITH_ASCEND_BACKEND )

# target listing all examples, to build them at once with 'make examples'
add_custom_target( examples)
Expand All @@ -31,3 +31,57 @@ if( WITH_OMP_BACKEND )
add_dependencies( examples sp_reference_omp )
endif()

if( WITH_ASCEND_BACKEND )
add_executable( alp_ascend_addOp_ascend unittests/alp_ascend_addOp.cpp )
target_link_libraries( alp_ascend_addOp_ascend backend_ascend common_flags )
add_dependencies( examples alp_ascend_addOp_ascend )
endif()

if( WITH_ASCEND_BACKEND )
add_executable( alp_ascend_addOpv1_ascend unittests/alp_ascend_addOpv1.cpp )
target_link_libraries( alp_ascend_addOpv1_ascend backend_ascend common_flags )
add_dependencies( examples alp_ascend_addOpv1_ascend )
endif()

if( WITH_ASCEND_BACKEND )
add_executable( alp_ascend_movedataOpv01_ascend unittests/alp_ascend_movedataOpv01.cpp )
target_link_libraries( alp_ascend_movedataOpv01_ascend backend_ascend common_flags )
add_dependencies( examples alp_ascend_movedataOpv01_ascend )
endif()

if( WITH_ASCEND_BACKEND )
add_executable( alp_ascend_softmaxOp_ascend unittests/alp_ascend_softmaxOp.cpp )
target_link_libraries( alp_ascend_softmaxOp_ascend backend_ascend common_flags )
add_dependencies( examples alp_ascend_softmaxOp_ascend )
endif()

if( WITH_ASCEND_BACKEND )
add_executable( alp_ascend_softmaxOpv1_ascend unittests/alp_ascend_softmaxOpv1.cpp )
target_link_libraries( alp_ascend_softmaxOpv1_ascend backend_ascend common_flags )
add_dependencies( examples alp_ascend_softmaxOpv1_ascend )
endif()

if( WITH_ASCEND_BACKEND )
add_executable( alp_ascend_softmaxOpv3_ascend unittests/alp_ascend_softmaxOpv3.cpp )
target_link_libraries( alp_ascend_softmaxOpv3_ascend backend_ascend common_flags )
add_dependencies( examples alp_ascend_softmaxOpv3_ascend )
endif()

if( WITH_ASCEND_BACKEND )
add_executable( alp_ascend_softmaxOpv4_ascend unittests/alp_ascend_softmaxOpv4.cpp )
target_link_libraries( alp_ascend_softmaxOpv4_ascend backend_ascend common_flags )
add_dependencies( examples alp_ascend_softmaxOpv4_ascend )
endif()

if( WITH_ASCEND_BACKEND )
add_executable( alp_ascend_onlinesoftmaxOp_ascend unittests/alp_ascend_onlinesoftmaxOp.cpp )
target_link_libraries( alp_ascend_onlinesoftmaxOp_ascend backend_ascend common_flags )
add_dependencies( examples alp_ascend_onlinesoftmaxOp_ascend )
endif()

if( WITH_ASCEND_BACKEND )
add_executable( ascend_flashattentionOp_ascend ascend_flashattentionOp.cpp )
target_link_libraries( ascend_flashattentionOp_ascend backend_ascend common_flags )
#add_dependencies( examples ascend_flashattentionOp_ascend )
endif()

11 changes: 11 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Makefile for the Ascend examples

.PHONY: all

all:
ascendcc -b 910B -c -o op.o op.cpp
ascendcc -I/home/yzelman/Packages/CANN/samples/cplusplus/level1_single_api/4_op_dev/6_ascendc_custom_op/kernel_invocation/kernel_template/ -b 910B -c -o op_host.o ../examples/ascend_host.cpp
ascendcc -o main.exe op.o op_host.o
LD_LIBRARY_PATH=/home/yzelman/Packages/CANN/x86_64/ascend-toolkit/latest/x86_64-linux/lib64/:/home/yzelman/Packages/CANN/x86_64/ascend-toolkit/latest/x86_64-linux/devlib/x86_64/ ./main.exe

108 changes: 108 additions & 0 deletions examples/alp_ascend_softMaxOp-manuallyTiled.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

/*
* Copyright 2021 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <iostream>
#include <sstream>
#include <vector>
#define DEBUG

#include <alpAscend.hpp>

using namespace alp;


// alp::Grid< 1, 4 > note:
// - Thread dimensionality = 1, means that the 1D thread grid maps to first
// axis of the problem grid. A refinement of this API may make this
// configurable.
template < typename GridType >
void ascend_code( const GridType &grid, RC &rc ) {
rc = alp::RC::FAILED;

Tensor Sin( alp::Datatype::FP16, make_axes( 0, 1, 2, 3 ) );
Tensor Sout( alp::Datatype::FP16, make_axes( 0, 1, 2, 3 ) );

rc = grid.forEach( make_axes( 0 ), [ & ] () {

auto S_block_in_ub = getView( Sin ); // T(1,2,3)
auto S_block_out_ub = getView( Sout ); // T(1,2,3)
Tensor localTensor_ub( alp::Datatype::FP16, make_axes( 1, 2 ) ); // T(1,2)

rc = grid.forEach( make_axes( 1 ), [ & ] () {

auto S_block_in = getView( S_block_in_ub ); // T(2,3)
auto S_block_out = getView( S_block_out_ub ); // T(2,3)
auto localTensor = getView( localTensor_ub ); // T(2)

// T(2) T(2,3)
apply( localTensor, S_block_in, "max", make_axes( 3 ) );
// T(2,3) T(2,3) T(2)
apply( S_block_out, S_block_in, localTensor, "minus", make_axes( 3 ) );
// T(2,3)
foldl( S_block_out, "exp" );
// T(2) T(2,3)
apply( localTensor, S_block_out, "add", make_axes( 3 ) );
// T(2,3) T(2)
foldl( S_block_out, localTensor, "divide", make_axes( 3 ) );
// T(2,3)

} );

store( S_block_out );

} );

return;
}

int main( int argc, char ** argv ) {

// default options
bool printUsage = false;

// input error checking
if( argc > 1 ) {
printUsage = true;
}

// print help on error
if( printUsage ) {
std::cerr << "Usage: " << argv[ 0 ] << "\n";
return 10;
}

// start opgen
std::cout << "//This is AscendOpGen example " << argv[ 0 ] << "\n";
alp::RC error_code = alp::RC::SUCCESS;
try {
error_code = alp::compile< 1, 4 >( ascend_code, "KernelSoftmax" );
} catch( std::exception &e ) {
std::cerr << "alp::compile threw error: " << e.what() << "\n";
return 20;
}
if( error_code != alp::RC::SUCCESS ) {
std::cerr << std::flush;
std::cout << "Codegen FAILED (" << alp::toString( error_code ) << ")"
<< std::endl;
return 30;
} else {
std::cout << "//Codegen OK" << std::endl;
return 0;
}

}

Loading
Loading