Install mxnet in R under Linux (step on every pit and cry)

If you just want to install the mxnet library, you can also refer to it

So far I have seen the most disgusting and disgusting software package, none of them, the first picture of a successful installationI cried when I saw this, really

Let’s talk about it first, if you want to watch the process directly, please turn it down. Thank you.

Click on the official website to see if you can only compile through source code under Linux. After you have read the build from source eagerly, you are ready to see if you generate an R package, https://mxnet.apache.org/get_started/build_from_source#install-the- mxnet-package-for-r, good guys, the link doesn’t have a jump, okay, then I’ll do the first step. After downloading apache-mxnet-src-1.7.0-incubating.tar.gz from the official website

$ cd apache-mxnet-src-1.7.0-incubating
$ mkdir _build
$ cmake ..

The operation is as fierce as a tiger, and it’s horrible to see if this error is reported.
Okay, look for other tutorials.
Finally I found a tutorial on github, which is still in Chinese https://github.com/devbib/mxnet/blob/ master/docs/zh/get_started/amazonlinux_setup_zh.md
didn't expect to make -j 24 directly and it would be done, so what is written on the official website? ? ?

No way, I can only continue to install it

$ cp make/config.mk .
$ make -j 4

After Kaka modified the configuration, why did Make prompt me that I was missing so many files? Sorry, there is a small line in the official website

$ git clone --recursive https://github.com/apache/incubator-mxnet mxnet

Why don't you write this directly? Asking everyone to download the compressed package really didn't understand, so why not give all the files inside? I really fell in love with the Buddha.

Do you think it's over here? Look at the big guy's tutorial again

$ cd R-package
$ Rscript -e "library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"
$ cd ..
$ make rpkg

Have you checked the things you provide? Is there an R-package folder? ? The most irritating thing is that there is no rpkg rule in your Makefile. I am really obsessed with it.

Have to tearfully install, the following detailed tutorial T...T

download

The first big pit is to download, just follow the steps below

$ git clone https://github.com/apache/incubator-mxnet.git--recursive 

The first git must add --recursive otherwise many packages will be missing

Sometimes some folders are missing because the author added these folders in .gitignore.
If you are using a chrome browser, you can add the plug-in gitZip for github and then double-click to download it.

Other browsers can Baidu some solutions by themselves

In this way, the content in the incubator-mxnet is complete, and R-package is the last file installed in R

Compile libmxnet.so

LAPACK is needed to compile mxnet, please install it yourself, you can refer to the article I wrote before

First compile the libmxnet.so library file, and finally install it into R

$ cd  incubator-mxnet
$ cp ./make/config.mk .
$ vim config.mk
# 在 USE_LAPACK 中添加上你的 lapcak 文件夹
-L/path/to/lapack-3.8.0
$ vim Makefile
# 找到 ifeq ($(USE_LAPACK), 1),在下方的 CFLAGS 中添加上 CBLAS 的 include 文件夹
CFLAGS += -DMXNET_USE_LAPACK -I/path/to/lapack-3.8.0/CBLAS/include
# 随后在 endif 后添加一句
LDFLAGS += -lgfortran
# 在最下方添加上编译 rpkg 的方法,在 1.6.x 版本中可以看到, 1.7.0 中不知道为什么作者将其移除了(黑人问号脸.jpg)
rpkg:
        mkdir -p R-package/inst/libs
        cp src/io/image_recordio.h R-package/src/image_recordio.h
        cp -rf lib/libmxnet.so R-package/inst/libs
        if [ -e "lib/libdnnl.so.1" ]; then \
                cp -rf lib/libdnnl.so.1 R-package/inst/libs; \
        fi
        if [ -e "lib/libtvm_runtime.so" ]; then \
                cp -rf lib/libtvm_runtime.so R-package/inst/libs; \
        fi
        mkdir -p R-package/inst/include
        cp -rl include/* R-package/inst/include
        Rscript -e "if(!require(devtools)){install.packages('devtools', repo = 'https://cloud.r-project.org/')}"
        Rscript -e "if(!require(roxygen2)||packageVersion('roxygen2') < '6.1.1'){install.packages('roxygen2', repo = 'https://cloud.r-project.org/')}"
        Rscript -e "library(devtools); library(methods); options(repos=c(CRAN='https://cloud.r-project.org/')); install_deps(pkg='R-package', dependencies = TRUE)"
        cp R-package/dummy.NAMESPACE R-package/NAMESPACE
        echo "import(Rcpp)" >> R-package/NAMESPACE
        R CMD INSTALL R-package
        Rscript -e "require(mxnet); mxnet:::mxnet.export('R-package'); warnings()"
        Rscript -e "devtools::document('R-package');warnings()"
        R CMD INSTALL R-package

The cblas library and -lgfortran must be added, or you need to recompile after reporting an error

You can also freely modify the config.mk file, such as supporting gpu, cuda acceleration, etc.

It takes a long time to compile the mxnet library. Please be sure to add these two places. The final rule can be added after the compilation is complete.

$ make -j 8
# 亲测,如果满核编译会报错,需要手动停止后继续编译,我的处理器是 24 核心,使用 -j 8 一般不会报错
$ ll lib/libmxnet.so

After the compilation is complete, check whether the libmxnet.so file is generated, and there are some operations that need to be performed manually

$ cd include 
$ rm dlpack  dmlc mshadow nnvm
$ cd mkldnn
$ rm dnnl.h  dnnl.hpp  dnnl_types.h mkldnn_dnnl_mangling.h  mkldnn.h  mkldnn.hpp  mkldnn_types.h  mkldnn_version.h

Delete all the soft links, and then re-use the full path link. The
original link is written with a relative path, and it will turn red when you use the cp operation later, causing it to be unusable.

$ Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"
$ cd R-package
$ Rscript -e "library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"
$ cd ..
$ make rpkg

If an error is reported... MXSetProfilerConfig(int, const char* const, const char* const) or something, perform the following operations

$ vim R-package/src/mxnet.cc
# 修改第27行
MX_CALL(0);

When executing Rscript -e "library(devtools); library(methods);, you will be asked to install tiff, imager and other packages.
Below is the error I encountered, if you don’t encounter it, you can skip

  1. When installing R tiff, it prompts that there is no tiff.h. At first, I was wondering why you lacked your own header files. It turns out that there is another library called tiff (please, normal people can think of...)
    Solution: Go online Download tiff_0.1-6.tar.gz and install it, and then make after configure.

    If you are in a conda virtual environment, you need to move the installed libtiff.so to /path/to/conda/lib, and move the files in the include folder to /path/to/conda/include

  2. When installing R tiff, you will be prompted to find the -ljpeg
    solution: install libjepg-turbo,

    $ git clone https://github.com/libjpeg-turbo/libjpeg-turbo.git
    $ cd libjpeg-turbo
    $ mkdir _build && cd _build
    $ cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install -G"Unix Makefiles" -DANDROID_ABI=x86_64
    
    

    Possible errors:

    jccolext-avx2.asm:290: error: parser: instruction expected
    jccolext-avx2.asm:292: error: symbol `vperm2i128' redefined

    reason: -G"Unix Makefiles" -DANDROID_ABI= x86_64
    solution: just add it in cmake

  3. An error occurred when installing R yaml:'yaml_emitter_t {aka struct yaml_emitter_s}' has no member named'indent_mapping_sequence'
    Reason: There is an old version of yaml installed.
    Solution: Uninstall the old version and reinstall it. There is one more step for the conda environment Need to be processed, refer to the article

  4. When installing R imager, it prompts that there is no X11
    solution: you can install it via conda: conda install -c conda-forge xorg-libx11

  5. Sometimes after the installation is complete, it will prompt X11 not found but required, configure aborted. After
    checking config.log, it prompts... XauGetBestAuthByAddr...
    Reason: The version of libXau.so.6 in the system is too low.
    Solution: conda install -c conda-forge xorg -libxau

  6. Finally, an error occurred after make rpkg, there is no opencv2/opencv.hpp
    solution: directly install opencv with conda, conda install -c conda-forge opencv

It's over, sprinkle flowers

Basically all the pits have been stepped on. It took 2 days. It is not easy. QAQ
If you have other problems, please leave a message or private message. I will basically reply when I see it.

Guess you like

Origin blog.csdn.net/qq_32115939/article/details/108829524