Windows下編譯kaldi--kaldi(二)


接着上一篇,openfst已經編譯好。

首先,使用git clone下載kaldi的項目

git clone https://github.com/kaldi-asr/kaldi.git kaldi

用4G網絡會快很多

1.

 

 

 這里有兩種選擇來使用BLAS,Intel® MKL and OpenBLAS.Intel® MKL is made by Intel and is optimised for their processors.It isn't free, but you can get Community Licensing for Intel® Performance Libraries or as part of Intel product suite if you qualify as students, educators, academic researchers, and open source contributors. OpenBLAS is free alternative with similar performance.(大致是說MKL不是免費的,但如果你是學生、教育工作者、搞學術研究的可以用社區版)(--要驗證很麻煩--)所以openBLAS是免費的可替代的,有着相似功能。

  1. If using Intel® MKL, install it.

  2. If using OpenBLAS, download the binary packages.

    https://sourceforge.net/projects/openblas

(kaldi)/tools$ curl -L -O http://sourceforge.net/projects/openblas/files/v0.2.14/OpenBLAS-v0.2.14-Win64-int32.zip
 (kaldi)/tools$ curl -L -O http://sourceforge.net/projects/openblas/files/v0.2.14/mingw64_dll.zip
 (kaldi)/tools$ unzip OpenBLAS-v0.2.14-Win64-int32.zip
 (kaldi)/tools$ unzip mingw64_dll.zip

Be careful to download "Win64-int32" and not "Win64-int64"!

一定要下32位的。http://sourceforge.net/projects/openblas/files/v0.2.14/OpenBLAS-v0.2.14-Win64-int32.zip/download

http://sourceforge.net/projects/openblas/files/v0.2.14/mingw64_dll.zip/download

 

 

 或者直接復制指令

 

 

 然后解壓。


 

For now, we do not support CUDA, nor provide any kind of assistance in getting it work. If you want enabled CUDA support, download and install NVIDIA CUDA SDK. Be careful and strive for as standard install as possible. The installer set certain environment variables on which the MSVC Build rules rely.(大意,迄今為止,我們不支持CUDA,或是提供任意一種幫助讓它運行。如果你想使CUDA能夠支持,下載並安裝CUDA SDK。保持小心並且盡可能使用標准安裝。安裝器要在MSVC編譯規則依賴的地方,設置確定的環境變量)

If you call "set" in the command line, you should see:

(kaldi)/tools $ set | grep CUDA
 CUDA_PATH='C:\Users\Yenda\Downloads\cuda'
 CUDA_PATH_V7_0='C:\Users\Yenda\Downloads\cuda'
 NVCUDASAMPLES7_0_ROOT='C:\Users\Yenda\Downloads\cuda'
 NVCUDASAMPLES_ROOT='C:\Users\Yenda\Downloads\cuda'

The first one (CUDA_PATH) is particularly important.

去官網下載CUDA

 

 

 


 

5.Enter the (kaldi)/windows directory

Example:  (kaldi)/$ cd windows (kaldi)/windows $ pwd 

6.Copy variables.props.dev to variables.props. Then modify the file variables.props to reflect the correct paths, using your favorite text editor. Don't worry, it's a text file, even though you have to be careful to keep the structure itself intact(將variables.props.dev復制一份,另存為variables.props; 然后打開后者,編輯使它映射到正確的路徑,並且保持結構完整)

If you plan to use MKL, you can ignore the OPENBLASDIR path. If you plan to use OpenBLAS, you can ignore the MKLDIR path. No matter what you plan to use, set OPENFST* variable correctly.

(用MKL的話,忽略OPENBLASDIR路徑。用OpenBLAS,則忽略MKLDIR路徑。無論用哪個,都要設置正確的OPENFST*變量)

For OpenBLAS support, copy the file kaldiwin_openblas.props to kaldiwin.props

For MKL support, copy the kaldiwin_mkl.props to kaldiwin.props

沒修改之前是這個樣子的

 

 

 修改成自己軟件所在的地址,沒有的不用改

    <!-- Change the following paths so they are correct on your machine -->
    <!-- Do not modify anything before this line -->
    <MKLDIR>C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\</MKLDIR>
    <OPENBLASDIR>D:\mc\kaldi-1\OpenBLAS-v0.2.14-Win64-int32</OPENBLASDIR>
    <OPENFST>D:\mc\kaldi-1\openfst</OPENFST>
    <OPENFSTLIB>D:\mc\kaldi-1\openfst\build64</OPENFSTLIB>
    <CUBDIR>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2</CUBDIR>
    <NVTOOLSDIR>C:\Program Files\NVIDIA Corporation\NvToolsExt</NVTOOLSDIR>
    <!-- Do not modify anything after this line -->

復制相應的文件

For OpenBLAS support, copy the file kaldiwin_openblas.props to kaldiwin.props

For MKL support, copy the kaldiwin_mkl.props to kaldiwin.props

生成解決方案

Call the script that generates the MSVC solution

 generate_solution.pl --vsver <default|vs2017|vs2015> [--enable-cuda] [--enable-openblas] [--enable-mkl]

 --enable-mkl is the default so you shouldn't need to use it. If --enable-openblas is passed it disables MKL support. CUDA is disabled by default. The default Visual Studio version is 15.0 (Visual Studio 2017). Please note that while we support generating the project for Visual Studio 2015, the C++11 support for that compiler is rather sub-par, i.e. it won't probably compile. When choosing Visual Studio 2015, you are on your own!

簡單來說<>中是單選,[]中參數可有可無,你有相應軟件就加上參數

例如,for a build using OpenBLAS and VS 2017 you would run:

(kaldi)/windows$ generate_solution.pl --vsver vs2017 --enable-openblas

Another example, for OpenBLAS, VS 2017 and CUDA support:

(kaldi)/windows$ generate_solution.pl --vsver vs2017 --enable-cuda --enable-openblas

 我這里用的是第二條指令。

 

 

 會生成一個kaldiwin_projguids.txt文件,則表示完成

Run the script (kaldi)/windows/get_version.pl:

(kaldi)/windows$ get_version.pl

文件內容如下,主要是把版本寫入version文件,沒有輸出表示一切正常
 1 #!/usr/bin/env perl
 2 #===============================================================================
 3 # Copyright 2017  (Author: Yenda Trmal <jtrmal@gmail.com>)
 4 #
 5 # Licensed under the Apache License, Version 2.0 (the "License");
 6 # you may not use this file except in compliance with the License.
 7 # You may obtain a copy of the License at
 8 #
 9 #  http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
12 # KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13 # WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
14 # MERCHANTABLITY OR NON-INFRINGEMENT.
15 # See the Apache 2 License for the specific language governing permissions and
16 # limitations under the License.
17 #===============================================================================
18 
19 use strict;
20 use warnings;
21 use utf8;
22 
23 open(my $F, "<", "../src/.version") or do {
24   print "$!\n";
25   print "The file ../src/.version does not exist\n";
26   print "Either you are not running this script from within\n";
27   print "the windows/ directory or you have accidently \n";
28   print "delete the file\n";
29   exit 1;
30 };
31 
32 open(my $H, ">", "../src/base/version.h") or do {
33   print "$!\n";
34   print "Could not write to ../src/base/version.h\n";
35   print "Either you are not running this script from within\n";
36   print "the windows/ directory or there were some other \n";
37   print "issues\n";
38   exit 1;
39 };
40 
41 my $kaldi_ver=<$F>; chomp $kaldi_ver;
42 print $H  "#define KALDI_VERSION \"${kaldi_ver}-win\"\n";
43 close($F);
44 close($H);
get_version.pl

Open the generated solution that was created in a subfolder (kaldi)/kaldiwin_vs_ in the visual studio and switch to Debug|x64 (or Release|x64) and build. Expect 10 projects to fail, majority of them will fail because of missing include portaudio.h. The tests will fail to compile too -- this is because of deficiency of the script generate_solution.pl. We might fix it later on.

編譯有錯誤。

如果sln都打不開,檢查第6步cuda路徑是否寫錯了

沒寫錯,但還是打不開

vs2017提示看輸出,輸出里會提示提示:未找到導入的項目“C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 7.0.props

解決方法:https://blog.csdn.net/xianhua7877/article/details/80795279

但是,把CUDA 7.0修改為自己的版本保存,不太可行,因為有1,286 個文件,639 個文件夾,所以反向操作一遍,打開VS提示的路徑,發現里面有CUDA 10.2.props,也就是前面在官網下載的,復制一份改成CUDA 7.0,輸入重定向,然后就能打開了

 

 

 將win32改成x64,生成項目,然后一堆紅

 

 

 Expect 10 projects to fail。總共10個需要升級,手動重定向一下,然后重新生成解決方案,

然后,只有這10個好了,其他幾百個都要升級,要不裝SDK8.1,要不全升級一遍

這里改好后,編譯online-wav-gmm-decode-fast 還是有許多問題,如下

 

 提示沒有mkl庫,安裝方法參見:https://blog.csdn.net/zb1165048017/article/details/70141432

沒有portaudio,到官網去下載:http://portaudio.com/download.html

最后SSIZE_T重定義,單擊找到type.h中ssize_t定義的位置

C2371:“identifier”:重定義;不同的基類型

已聲明該標識符。說明已經定義了不用重新定義

#ifdef _MSC_VER
// Not really Windows-specific: they should have used ptrdiff_t in the first
// place. But on Windows there has never been ssize_t.
using ssize_t = std::ptrdiff_t;
#endif  // _MSC_VER
types.h

打開kaldi-types.h 發現第35行 define ssize_t SSIZE_T 使用了這個標識符,從而

導致types.h里的聲明失效,直接注釋掉這一行,重新編譯生成,結果成功生成項目

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM