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

build mkldnn as static lib on mac/linux #13197

Closed
wants to merge 29 commits into from

Conversation

azai91
Copy link
Contributor

@azai91 azai91 commented Nov 9, 2018

Description

currently MKLDNN is dynamically linked to mxnet. This can cause some issues if another version of mkldnn is present on the host machine and mxnet links to the host version. This change statically builds mkldnn into mxnet to handle version issues on linux/mac but keeps it dynamically linked on windows.

removed test_mkldnn_install.py from test as well since it tests if mkldnn is dynamically linked on linux (which it is no longe)

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

  • set property in cmake that causes mkldnn to statically link to mxnet

Comments

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

@azai91 azai91 requested a review from szha as a code owner November 9, 2018 02:16
@harshp8l
Copy link
Contributor

harshp8l commented Nov 9, 2018

@mxnet-label-bot add [mkldnn, build]

@kalyc
Copy link
Contributor

kalyc commented Nov 14, 2018

@mxnet-label-bot add [pr-work-in-progress]

@marcoabreu marcoabreu added the pr-work-in-progress PR is still work in progress label Nov 14, 2018
@azai91
Copy link
Contributor Author

azai91 commented Nov 15, 2018

@marcoabreu do you have any idea why mxnet_unit_test still links to libmkldnn.so.0?

@azai91
Copy link
Contributor Author

azai91 commented Nov 20, 2018

@TaoLv can you take a look at this and help me find where we still link libmkldnn.so.0 in the CI?

Copy link
Member

@TaoLv TaoLv left a comment

Choose a reason for hiding this comment

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

CMakeLists.txt Outdated
@@ -225,6 +225,7 @@ endif()

if(USE_MKLDNN)
include(cmake/DownloadMKLML.cmake)
SET(MKLDNN_LIBRARY_TYPE STATIC)
Copy link
Member

Choose a reason for hiding this comment

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

Try set(MKLDNN_LIBRARY_TYPE "STATIC" CACHE INTERNAL "" FORCE)

@azai91 azai91 changed the title build mkldnn as static lib build mkldnn as static lib on mac/linux Nov 30, 2018
@azai91
Copy link
Contributor Author

azai91 commented Nov 30, 2018

@TaoLv can you review this diff? prefer getting this merged before merging / fixing #13464 as there are quite a few changes to the CI that is needed.

Copy link
Contributor

@Vikas-kum Vikas-kum left a comment

Choose a reason for hiding this comment

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

Looks good!

Makefile Outdated

ifneq ($(UNAME_S), Windows)
LIB_DEP += $(MKLDNNROOT)/lib/libmkldnn.a
else
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation does not look right, could you please double check?

Makefile Outdated
else
CFLAGS += -I$(MKLDNNROOT)/include
LDFLAGS += -L$(MKLDNNROOT)/lib -lmkldnn -Wl,-rpath,'$${ORIGIN}'
endif
Copy link
Member

Choose a reason for hiding this comment

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

nit: indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's for the ifeq on line 126.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this aligned with L126 then?

ifeq ($(UNAME_S), Darwin)
OMP_LIBFILE = $(MKLDNNROOT)/lib/libiomp5.dylib
MKLML_LIBFILE = $(MKLDNNROOT)/lib/libmklml.dylib
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.0.dylib
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.a
else ifeq ($(UNAME_S), Windows)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a endif for this ifeq? Maybe better to break the line so it will be shown RED in web browser?

Copy link
Contributor

Choose a reason for hiding this comment

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

NVM, seems this is correct syntax in Makefile.

Copy link
Contributor

@apeforest apeforest left a comment

Choose a reason for hiding this comment

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

LGTM

CFLAGS += -I$(MKLDNNROOT)/include
LDFLAGS += -L$(MKLDNNROOT)/lib -lmkldnn -Wl,-rpath,'$${ORIGIN}'

ifneq ($(UNAME_S), Windows)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a reason here, on why on Windows, it is dynamically linked for future maintenance?

Copy link
Member

Choose a reason for hiding this comment

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

+1 for adding comments. Also curious about how MKL BLAS is linked on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated comment in #13503.

@sandeep-krishnamurthy
Copy link
Contributor

Re-triggering failed CI.

@azai91 azai91 mentioned this pull request Dec 1, 2018
7 tasks
CFLAGS += -I$(MKLDNNROOT)/include
LDFLAGS += -L$(MKLDNNROOT)/lib -lmkldnn -Wl,-rpath,'$${ORIGIN}'

ifneq ($(UNAME_S), Windows)
Copy link
Member

Choose a reason for hiding this comment

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

+1 for adding comments. Also curious about how MKL BLAS is linked on Windows?



if __name__ == '__main__':
install.test_mkldnn_install()
Copy link
Member

Choose a reason for hiding this comment

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

Need make sure about the purpose of a test case before removing it. If this case is just for verifying whether MKL-DNN so is correctly linked, I'm OK with removing it. Otherwise, need replace it with something else.

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 test looks if mkldnn appears on the memory table of the process running mxnet.I have verified manually (by cat /proc/{id}/maps | grep mkldnn) that mkldnn use to appear in the table when it is dynamically linked but no longer does (statically linked).

the second part of this just checks the response code (rc - probably to make sure the proc/{id}/maps file even exists).

@pengzhao-intel is there another reason this test was added

@azai91
Copy link
Contributor Author

azai91 commented Dec 3, 2018

#13503 has been merged. closing this PR.

@azai91 azai91 closed this Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Build MKLDNN pr-work-in-progress PR is still work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants