-
Notifications
You must be signed in to change notification settings - Fork 326
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
[NNPA] Add numerical test for NNPA #1335
Conversation
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
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.
The code changes are good. I would like for you to add a document page on AccelNNPAHowToUseAndTest.md
and list the explanation that you gave on the conversation. Over time, this page will add more info.
Please make this addition part of this PR. Thanks
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
I will remove backend test from this PR because we need to discuss how to set ATOL and RTOL for backend test. We need to set them to pass backend test on NNPA. |
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
@jenkins-droid test this please |
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.
Its going in the right directions, and the new infrastructure about testing for the ops is very helpful. Thanks
test/modellib/ModelLib.cpp
Outdated
dptr = (int *)dlsym(handle, instructionName.c_str()); | ||
if (dptr == NULL) { | ||
printf("%s\n", dlerror()); | ||
return false; |
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.
If you look at the code in ExecutionSession builder, there is already code that can load a library without being specific to windows or linux.
_sharedLibraryHandle =
llvm::sys::DynamicLibrary::getPermanentLibrary(sharedLibPath.c_str());
if (!_sharedLibraryHandle.isValid())
throw std::runtime_error(reportLibraryOpeningError(sharedLibPath));
The execution session also look for specific entries, so I would investigate if we can reuse the OS agnostic methods developed by LLVM.
IN particular, we also look there if a given function is found or not, for example
_queryEntryPointsFunc = reinterpret_cast<queryEntryPointsFuncType>(
_sharedLibraryHandle.getAddressOfSymbol(_queryEntryPointsName.c_str()));
if (!_queryEntryPointsFunc)
throw std::runtime_error(reportSymbolLoadingError(_queryEntryPointsName));
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
This reverts commit 6bb232f. Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
@imaihal let me know when you have all your changes in, and I will review again. |
@AlexandreEichenberger Yes. Now ready for review again. Thanks! |
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.
@tungld I created checkSharedLibInstruction() to verify instructions in shared library. We can verify that zDNN instructions are included automatically by using the function.
Thanks so much! It's useful.
The current code looks good to me with some minor changes to make things consistent. Please wait for Alex's input too.
In the future, we can improve the code with two things:
checkInstructionFromEnv
should support multiple instructions since one ONNX op may call multiple zDNN ops.gemm.compileAndLoad() && gemm.checkInstructionFromEnv()
.compileAndLoad
has loaded the shared library, no need to load it again incheckInstructionFromEnv
. To do that, we should edit ExecutionSession so that we can get the loaded library from it.
test/modellib/ModelLib.cpp
Outdated
std::string instructionName = | ||
getenv("TEST_CHECK_INSTRUCTION") ? getenv("TEST_CHECK_INSTRUCTION") : ""; | ||
if (instructionName.empty()) | ||
return true; |
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.
This looks redundant since checkInstruction(instructionName)
also checks empty string.
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.
Please pass the env var name as a parameter. Its easier to read all the param in the specific test file, e.g. TestMatMul2D....
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.
Done. Thanks!
test/numerical/TestGemm.cpp
Outdated
@@ -92,10 +93,15 @@ int main(int argc, char *argv[]) { | |||
const auto aTrans = *rc::gen::inRange(0, 2); | |||
const auto bTrans = *rc::gen::inRange(0, 2); | |||
const auto cRank = *rc::gen::inRange(1, 3); | |||
#ifdef TEST_ALPHA_BETA_1 |
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.
Suggest to use a more specific name, say TEST_GEMM_ALPHA_BETA_1
.
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.
Done. Thanks!
test/numerical/TestLSTM.cpp
Outdated
@@ -70,14 +80,23 @@ int main(int argc, char *argv[]) { | |||
// Whether initial value of the cell(initial_c) is specified. | |||
const auto isNoneC = *rc::gen::element(0, 1); | |||
// Whether the weight tensor for peepholes(P) is specified. | |||
#ifdef TEST_NONEP_ONLY |
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.
Suggest to use TEST_LSTM_NO_P
or TEST_LSTM_NO_PEEPHOLE
to make it consistent with the other environment variables.
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.
Done. Thanks!
LINK_LIBS PRIVATE ${TEST_LINK_LIBS} | ||
) | ||
|
||
add_numerical_unittest(TestGemm-NNPA zdnn_matmul_op |
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.
Could we check multiple zdnn functions here? For example, some GEMM ops will use both zdnn_matmul_op
and zdnn_add_op
. It's ok to implement this with another PR.
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.
Thanks for your comments!
It is possible to check multiple functions, but currently it is not easy to select one function from those multiple functions in each testcase.
For example in GEMM, zdnn_matmul_op
and zdnn_add_op
can be checked in all testcases of GEMM, but it is not possible to select only zdnn_matmul_op
in some testcases and zdnn_matmul_op
and zdnn_add_op
in the other testcases. I think we need another config for each testcase.
So, I would like to set this TODO for now.
definitely, just add llvm::sys::DynamicLibrary &getDynLibraryHandle() { return _sharedLibraryHandle }; |
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.
Almost there... please implement the changes suggested by Tung and I. The added functionality of handing a list of instructions to check should probably let for a subsequent PR.
I will approve it now so that you may merge it once the above changes are made. Big thanks.
test/modellib/ModelLib.cpp
Outdated
std::string instructionName = | ||
getenv("TEST_CHECK_INSTRUCTION") ? getenv("TEST_CHECK_INSTRUCTION") : ""; | ||
if (instructionName.empty()) | ||
return true; |
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.
Please pass the env var name as a parameter. Its easier to read all the param in the specific test file, e.g. TestMatMul2D....
if (instructionName.empty()) | ||
return true; | ||
std::string sharedLibName = getSharedLibName(sharedLibBaseName); | ||
llvm::sys::DynamicLibrary sharedLibraryHandle = |
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.
Please extract the library from the ExecutionSession model variable onnx_mlir::ExecutionSession *exec;
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.
Done. Thanks!
@@ -40,8 +40,9 @@ bool isOMConvTheSameAsNaiveImplFor(const int N, const int C, const int H, | |||
|
|||
Conv2DLibBuilder conv(SHARED_LIB_BASE.str(), N, C, H, W, kH, kW, autoPad, | |||
pHBegin, pHEnd, pWBegin, pWEnd, stride, dilation, isDynamic); | |||
return conv.build() && conv.compileAndLoad() && conv.prepareInputs() && | |||
conv.run() && conv.verifyOutputs(); | |||
return conv.build() && conv.compileAndLoad() && |
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.
It looks SOOO much better, thanks for the changes.
…ction Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Signed-off-by: Haruki Imai <imaihal@jp.ibm.com>
Jenkins Linux ppc64le Build #5206 [push] [NNPA] Add numerical tes... started at 06:22 |
Jenkins Linux s390x Build #6084 [push] [NNPA] Add numerical tes... started at 06:19 |
Jenkins Linux amd64 Build #6069 [push] [NNPA] Add numerical tes... started at 05:19 |
Jenkins Linux s390x Build #6084 [push] [NNPA] Add numerical tes... passed after 1 hr 0 min |
Jenkins Linux ppc64le Build #5206 [push] [NNPA] Add numerical tes... passed after 1 hr 13 min |
Jenkins Linux amd64 Build #6069 [push] [NNPA] Add numerical tes... passed after 1 hr 14 min |
This PR adds numerical tests for NNPA.
Currently tests for MatMul2D, Gemm, LSTM, and GRU are provided and run by using following command.
These tests uses the same test code with numerical tests for CPU (
test/modellib
andtest/numerial
), but uses different cmake file(test/accelerator/NNPA/numerical/CMakeLists.txt
).Since
alpha
andbeta
should be one for Matmul of zDNN library, #ifdef directiveTEST_GEMM_ALPHA_BETA_1
are added intest/numerical/TestGemm.cpp
and set in the CMakeLists.txt (test/accelerator/NNPA/numerical/CMakeLists.txt
)Since LSTM of zDNN library does not support peephole tensor, #ifdef directive
TEST_LSTM_NONEP_ONLY
are added intest/numerial/TestLSTM.cpp
and set in the CMakeLists.Currently bidirectinal LSTM is not supported in onnx-mlir for NNPA, so, it is disabled by using #ifdef directive
TEST_RNN_NO_BIDIR
Since GRU of zDNN library does not support LinearBeforeReset, #ifdef directive
TEST_GRU_L1
are added intest/numerial/TestGRU.cpp
and set in the CMakeLists.Currently bidirectinal LSTM is not supported in onnx-mlir for NNPA, so, it is disabled by using #ifdef directive
TEST_RNN_NO_BIDIR
To use these #ifdef directives, this PR updated
add_onnx_mlir_executable()
in MLIR.cmake.ATOL and RTOL for accuracy check
ATOL and RTOL need to be changed for tests. They are configured by environment variable
TEST_ATOL
andTES_RTOL
in CMakeLists.txt.Verification that zDNN instruction are generated in shared library
checkInstructionFromEnv()
in ModelLibBuilder verifies that the instruction specified the environment variable is included in generated shared library. The instructions such aszdnn_matmul_op
,zdnn_lstm
, andzdnn_gru
are specified in CMakeLists.txt.Test results on a machine with NNPA (I removed the elapsed time because I don't know if I can publish it here.)