問題描述
我的目標是將 LAPACK 與 Emscripten 一起使用.
My goal is to use LAPACK with Emscripten.
我的問題是:如何將 LAPACK 移植到 JS?我能想到的方法有兩種: CLAPACK to JS 我的問題是:有人知道 3.2.1 之后的非官方版本嗎?而另一種思路是:如何將FORTRAN移植到JS?
My question is: how to port LAPACK to JS? The are two ways I can think of: CLAPACK to JS where my question is: does anybody know an unofficial version that is later than 3.2.1? And the other way to think of is: how to port FORTRAN to JS?
Emscripten 能夠將 C 代碼轉換為 JavaScript.但不幸的是,LAPACK 3.5.0 (http://www.netlib.org/lapack/) 僅在 FORTRAN95 中可用.
Emscripten is capable of transforming C code to JavaScript. But unfortunately, LAPACK 3.5.0 (http://www.netlib.org/lapack/) is only available in FORTRAN95.
CLAPACK 項目 (http://www.netlib.org/clapack/) 基本上就是我想要的:C 版本的 LAPACK.但是這個已經過時了;最新的是 3.2.1.
The CLAPACK project (http://www.netlib.org/clapack/) is basically what I want: a C version of LAPACK. But this one is outdated; the latest is 3.2.1.
F2C 僅適用于 FORTRAN 77.LAPACK 3.5.0 是用 FORTRAN 95 編寫的.
F2C only works up to FORTRAN 77. LAPACK 3.5.0 was written in FORTRAN 95.
所以我現在的問題是:為什么沒有 LAPACK 到 C 的更新端口?
So my question now is: why is there no newer port of LAPACK to C?
最好的方法是直接將LAPACK的FORTRAN95代碼轉換成帶有clang和emscripten的javascript.但我只是不知道從哪里開始.
The optimal way would be to directly transform the FORTRAN95 code of LAPACK to javascript with clang and emscripten. But I just don't know where to start.
Emscripten 目前不支持 FORTRAN.但它處理 LLVM 位碼,所以使用 clang 從 FORTRAN 文件生成 LLVM bc 應該不是問題.
Emscripten currently does not support FORTRAN. But it handles LLVM bitcode, so it should not be a problem to use clang to generate LLVM bc from a FORTRAN file.
出于測試目的,我有這個文件:
For testing purpose, I have this file:
program hello
print *, "Hello World!"
end program hello
它可以用clang hello.f -o hello -lgfortran"編譯得很好.我無法將其轉換為有效的位碼.
It compiles just fine with "clang hello.f -o hello -lgfortran". I am not capable of transforming this into valid bitcode.
clang -c -emit-llvm hello.f
clang -S -emit-llvm hello.f -o hello.bc -lgfortran
這些方法都不起作用,因為 emscripten 一直在告訴我
None of these approaches works, because emscripten keeps telling me
emcc -c hello.o -o hello.js
hello.o is not valid LLVM bitcode
我不確定這是否可能,因為 LAPACK 顯然需要 libgfortran 才能工作.而且我無法將庫合并到 javascript 代碼中...
I am not sure anyways if this would be even possible, because LAPACK obviously needs libgfortran to work. And I can't merge a library into javascript code...
提前致謝!
我幾乎設法將 BLAS 從 LAPACK 3.5.0 轉換為 JS.我用dragonegg來完成這個.
I almost managed it to convert BLAS from LAPACK 3.5.0 to JS. I used dragonegg to accomplish this.
gfortran caxpy.f -flto -S -fplugin=/usr/lib/gcc/x86_64-linux-gnu/4.6/plugin/dragonegg.so
gfortran cgerc.f ...
...
從中獲得 LLVM 位碼后:
After gaining LLVM bitcode from that:
emcc caxpy.s.ll cgerc.s.ll cher.s.ll ... -o blas.js -s EXPORTED_FUNCTIONS="['_caxpy_', ... , '_ztpsv_']"
但是 emscripten 仍然給我留下以下錯誤:
But emscripten still leaves me with the following errors:
warning: unresolved symbol: _gfortran_st_write
warning: unresolved symbol: _gfortran_string_len_trim
warning: unresolved symbol: _gfortran_transfer_character_write
warning: unresolved symbol: _gfortran_transfer_integer_write
warning: unresolved symbol: _gfortran_st_write_done
warning: unresolved symbol: _gfortran_stop_string
warning: unresolved symbol: cabs
warning: unresolved symbol: cabsf
AssertionError: Did not receive forwarded data in an output - process failed?
問題是我認為 lgfortran 是預編譯的.
The problem is that lgfortran is precompiled I think.
推薦答案
感謝您的回復!事實上,我確實在這方面取得了進展.最后它正在工作.我非常接近,只需按照以下步驟操作:
Thank you for your reply! Indeed I did make progress on this. Finally it is working. I was very close, just follow these steps:
gfortran caxpy.f -S -flto -m32 -fplugin=dragonegg.so
mv caxpy.s caxpy.ll
llvm-as caxpy.ll -o caxpy.o
注意我之前錯過的m32"標志.
Note the "m32" flag which I missed earlier.
類似警告
warning: unresolved symbol: _gfortran_st_write
可以安全地忽略.Emscripten 在 JavaScript 文件中使用此名稱創建空函數,因此如果根本不調用這些函數,則沒有問題.如果它們被調用,您可以輕松地將它們替換為您自己的函數;這些名稱有點描述性.此外,您可以查看 libgfortran 源代碼(注意它是 GPL).
can be ignored safely. Emscripten creates empty functions in the JavaScript file with this name so if these functions are not called at all there is no problem. If they get called you can easily substitute them with your own functions; the names are somewhat descriptive. Additionally you can have a look at the libgfortran source code (be aware it is GPL).
有了這個 Emscripten 源可以手動擴展以支持 Fortran 文件.有一天我可能會在 github 上發布這個!
With this Emscripten source can be extended by hand to support Fortran files. Someday I may publish this on github!
這篇關于將 Emscripten 與 Fortran 一起使用:LAPACK 綁定的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!