Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[WIP] CMake NNPack support #9860

Closed
wants to merge 94 commits into from
Closed

[WIP] CMake NNPack support #9860

wants to merge 94 commits into from

Conversation

dabraude
Copy link
Contributor

@dabraude dabraude commented Feb 22, 2018

Description

This is the first part of #9719

Checklist

Essentials

  • Passed code style checking (make lint)
  • [] Changes are complete (i.e. I finished coding on this PR)
  • [] All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • [N/A] Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Added option to CMake to build with NNPack support

Comments

  • NNPack and dependencies are located in subdirectory of 3rdparty
  • Some source files needed changes to reflect new location
  • This does make the website documentation on compiling NNPack obsolete

@Maratyszcza may want to check that everything is correct with regards to imports

Next up is refactoring the operators

@dabraude dabraude changed the title Nnpack CMake NNPack support Feb 22, 2018
@dabraude
Copy link
Contributor Author

The test that failed is flaky #9856

@dabraude dabraude changed the title CMake NNPack support [WIP] CMake NNPack support Feb 22, 2018
David Braude and others added 6 commits February 22, 2018 12:16
MXInitialise
Readies mxnet for use. While this is possible with some other commands this function makes more sense and does not require unneeded variables.

MXNDArrayLoadListFromMemory
Duplicates MXNDArrayLoad but from a location in memory. This was needed for my work as we bundle models into another file.
Copy link
Contributor

@marcoabreu marcoabreu left a comment

Choose a reason for hiding this comment

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

What's the deal with all the uncommented code?

CMakeLists.txt Outdated
# ---[ NNPack
if(USE_NNPACK)
if (USE_MKLDNN)
message(WARNING "With MKLDNN enabled NNPack operators will not run.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? What happens in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

both MKLDNN and NNPack define CPU versions of some operators, while there won't be an issue with compilation, when these operators are invoked they will need to use only the one backend.

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if a user invokes one of these operators?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I'm coding it, it will use the mkldnn backend. Once I finish that maybe some testing would show that NNPack is faster in which case it can be changed to the default.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of such implicit actions. It should be up to the user to decide which Backend to use. To me, setting both options seems like a conflict and should fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it to fail in that case.

@dabraude
Copy link
Contributor Author

I wasn't going to push but I had conflicts with the upstream/master that needed to be resolved.

The problem is that none of the old implementation of the operators would work, but I would like to keep them as a reference while I code new versions.

set(CONFU_DEPENDENCIES_BINARY_DIR "${CMAKE_BINARY_DIR}/3rdparty/NNPACK/deps"
CACHE PATH "Confu-style dependencies source directory")

add_subdirectory("${NNPACK_SOURCE_DIR}")
Copy link

Choose a reason for hiding this comment

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

I'd suggest to do set the following variables:

set(NNPACK_BUILD_TESTS OFF CACHE BOOL "")
set(NNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "")
set(NNPACK_LIBRARY_TYPE "static" CACHE STRING "")
set(PTHREADPOOL_LIBRARY_TYPE "static" CACHE STRING "")
set(CPUINFO_LIBRARY_TYPE "static" CACHE STRING "")

NNPACK_BUILD_TESTS and NNPACK_BUILD_BENCHMARKS disabled building NNPACK's own tests and benchmarks (which are enabled by default), and setting NNPACK_LIBRARY_TYPE, PTHREADPOOL_LIBRARY_TYPE and CPUINFO_LIBRARY_TYPE as "static" would build these projects as static libraries even if BUILD_SHARED_LIBS is ON.

After add_subdirectory, you'd likely want to add

set_property(TARGET nnpack PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET pthreadpool PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON)

to build nnpack, pthreadpool, and cpuinfo with -fPIC even through they are static libraries.

@CodingCat
Copy link
Contributor

Hi, the community has passed to vote about associating the code changes with JIRA (https://lists.apache.org/thread.html/ab22cf0e35f1bce2c3bf3bec2bc5b85a9583a3fe7fd56ba1bbade55f@%3Cdev.mxnet.apache.org%3E)

We have updated the guidelines for contributors in https://cwiki.apache.org/confluence/display/MXNET/Development+Process, please ensure that you have created a JIRA at https://issues.apache.org/jira/projects/MXNET/issues/ to describe your work in this pull request and include the JIRA title in your PR as [MXNET-xxxx] your title where MXNET-xxxx is the JIRA id

Thanks!

@szha
Copy link
Member

szha commented Jun 30, 2018

Hi @dabraude. Thanks for the patch and for proposing the support. Given that this PR hasn't been updated for quite a while and the many changes in our CI, it would be great if you could create a new PR for this change. Thank you.

@szha szha closed this Jun 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants