-
Notifications
You must be signed in to change notification settings - Fork 4
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
djelovina
wants to merge
2
commits into
develop
Choose a base branch
from
653-alp-ascend-opgen
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?