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

Fix PR #15489 (Dynamic Library Loading Support) #15760

Merged
merged 6 commits into from
Aug 8, 2019
Merged

Conversation

mseth10
Copy link
Contributor

@mseth10 mseth10 commented Aug 6, 2019

Description

This PR builds on top of #15489, which was reverted by #15755.

It includes the following additional changes:

  • Changes to Makefile and CMake flows to build sample library as part of MXNet build
  • Modifications to CI to stash/un-stash the library binary from build stage to test stage
  • Loads the binary as part of unit test

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • 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)
  • 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
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@mseth10 mseth10 requested a review from szha as a code owner August 6, 2019 01:15
@mseth10 mseth10 changed the title build sample library in CI [WIP] build sample library in CI Aug 6, 2019
@mseth10 mseth10 force-pushed the ext_lib branch 4 times, most recently from 3192333 to aafed25 Compare August 6, 2019 21:52
mseth10 and others added 3 commits August 7, 2019 17:58
* Accelerator APIs header file

* adding example to test accelerator loading

* adding c_api function header

* modifying header file path

* creating templates for call to lib fns

* modifying target to mxnet_static for libdl

* rebaseing with master

* returning nullptr handle if library not loaded

* refactoring code to load libraries dynamically

* addressing review comments

* using static cast

* pylint fix

* moving library.h file to src/common/

* adding dynamic loading support for windows

* updating header guard

* fixing headers

* fixing windows casting error

* declaring library functions for windows

* adding library testing module in examples

* adding unit test to test library loading

* correcting file names

* updating error messages

* getting error message from DL library

* adding unit test to gpu suite

* correcting windows pointer

* requiring absolute path to library

* changing file description

* addressing review comments - adding more docs, windows error msg

* addressing PR comments

* checking machine type for unit test

* “re-trigger”

* added map to store loaded libraries

* added dlclose calls in naive & threaded engines

* removed library map declaration in cc file

* added windows free

* fixed formatting

* added cast to HMODULE for void* for windows

* retrigger CI for flaky unix_cpu
@mseth10 mseth10 changed the title [WIP] build sample library in CI Fix PR #15489 (Dynamic Library Loading Support) Aug 7, 2019
# under the License.

all:
g++ -shared -fPIC mylib.cc -o mylib.so -I ../../include/mxnet
Copy link
Contributor

@larroy larroy Aug 7, 2019

Choose a reason for hiding this comment

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

If CI doesn't pass, I suggest to use $(CC) and $(CXX) and parameterize the linker so it's coming from environment as usual instead of hardcoded, if not it's not worth another CI round.

Copy link
Contributor

@samskalicky samskalicky Aug 7, 2019

Choose a reason for hiding this comment

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

@larroy this isnt building in the CI. this is just an example. See changes in the other Makefile or CMakeLists.txt for changes to build the library in the CI

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand, but still this is a PITA if a Makefile doesn't respect the compiler from the environment. That's why I said is not worth another CI round. If you make other changes I would change it. Or is there a reason not to?

Copy link
Contributor

Choose a reason for hiding this comment

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

How does that work for windows? will it automatically have CXX be "cl" ?

Copy link
Contributor

@larroy larroy left a comment

Choose a reason for hiding this comment

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

Two questions, and one issue regarding close. Rest looks good.

* \return func a function pointer
*/
template<typename T>
T get_func(void *lib, char *func_name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want to get funky inside a mxnet namespace?

src/engine/threaded_engine.h Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Copy link
Contributor

@larroy larroy left a comment

Choose a reason for hiding this comment

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

LGTM I will move loaded_libs to LibraryInitializer singleton, since I have a PR open I can do it there after this is merged.

@zachgk zachgk merged commit a2b11ae into apache:master Aug 8, 2019
#include "dmlc/io.h"

// map of libraries loaded
static std::map<std::string, void*> loaded_libs;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be static in a header. I will change it in my PR. This creates a symbol in every compilation unit.

anirudhacharya pushed a commit to anirudhacharya/mxnet that referenced this pull request Aug 20, 2019
* Dynamic Library Loading Support (apache#15489)

* Accelerator APIs header file

* adding example to test accelerator loading

* adding c_api function header

* modifying header file path

* creating templates for call to lib fns

* modifying target to mxnet_static for libdl

* rebaseing with master

* returning nullptr handle if library not loaded

* refactoring code to load libraries dynamically

* addressing review comments

* using static cast

* pylint fix

* moving library.h file to src/common/

* adding dynamic loading support for windows

* updating header guard

* fixing headers

* fixing windows casting error

* declaring library functions for windows

* adding library testing module in examples

* adding unit test to test library loading

* correcting file names

* updating error messages

* getting error message from DL library

* adding unit test to gpu suite

* correcting windows pointer

* requiring absolute path to library

* changing file description

* addressing review comments - adding more docs, windows error msg

* addressing PR comments

* checking machine type for unit test

* “re-trigger”

* added map to store loaded libraries

* added dlclose calls in naive & threaded engines

* removed library map declaration in cc file

* added windows free

* fixed formatting

* added cast to HMODULE for void* for windows

* retrigger CI for flaky unix_cpu

* build library and stash it in CI

* modifying unittest to use CI built binary

* Retrigger CI

* adding dlclose to initialize destructor

* adding sample_lib target to all in Makefile
Makefile Show resolved Hide resolved
access2rohit pushed a commit to access2rohit/incubator-mxnet that referenced this pull request Sep 25, 2019
* Dynamic Library Loading Support (apache#15489)

* Accelerator APIs header file

* adding example to test accelerator loading

* adding c_api function header

* modifying header file path

* creating templates for call to lib fns

* modifying target to mxnet_static for libdl

* rebaseing with master

* returning nullptr handle if library not loaded

* refactoring code to load libraries dynamically

* addressing review comments

* using static cast

* pylint fix

* moving library.h file to src/common/

* adding dynamic loading support for windows

* updating header guard

* fixing headers

* fixing windows casting error

* declaring library functions for windows

* adding library testing module in examples

* adding unit test to test library loading

* correcting file names

* updating error messages

* getting error message from DL library

* adding unit test to gpu suite

* correcting windows pointer

* requiring absolute path to library

* changing file description

* addressing review comments - adding more docs, windows error msg

* addressing PR comments

* checking machine type for unit test

* “re-trigger”

* added map to store loaded libraries

* added dlclose calls in naive & threaded engines

* removed library map declaration in cc file

* added windows free

* fixed formatting

* added cast to HMODULE for void* for windows

* retrigger CI for flaky unix_cpu

* build library and stash it in CI

* modifying unittest to use CI built binary

* Retrigger CI

* adding dlclose to initialize destructor

* adding sample_lib target to all in Makefile
@samskalicky samskalicky mentioned this pull request Dec 13, 2019
4 tasks
@mseth10 mseth10 deleted the ext_lib branch June 1, 2020 10:47
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.

6 participants