-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vegan for webR / wasm #623
Comments
No idea. Why don't you try? |
I'd be very surprised if the reason that vegan isn't already compiled is because someone forgot to compile it. I suspect some mix of the Fortran or C code in the package is currently not something that is easily amenable to the emscripten compilation process. |
vegan is not available in the automatic builds from CRAN in https://repo.r-wasm.org. Obviously it fails. We can speculate for the reason, but that's futile: we should know why it failed to build. However, here some speculation: we have three kind of call interface to compiled code:
webR/wasm claims to be able to handle C, C++ and Fortran and from that point of view these should work. R assumes all these interfaces look similar to the calling function, and base R uses all of these. It is unclear to me if webR/wasm needs something special to handle all these. Please note that More useless (in lack of logs) speculation: the wasm build seems to use That was all background that can only become useful after we get the failure logs and see where is the problem. Without logs there is nothing we can do. Anybody can produce or access such logs? |
I dont think i have the technical knowledge to try to build it. |
what's interesting is that vegan is a dependency of GUniFrac, but GUniFrac is available for webR does that mean that they have compiled vegan ? |
@isbool GUniFrac is available, but they say that not all dependences are available, and vegan is listed as missing dependence. I don't know what are the criteria for this decision. The repo makes available a huge number of packages with missing dependencies: when writing this, the wasm repo had 19867 packages, but only 11773 had all their dependencies satisfied (CRAN had 20526 packages when writing this). |
@jarioksa i tried to compile it (using this proccess with docker) i get this: > build("vegan")
v Updated metadata database: 6.19 MB in 4 files.
v Updating metadata database ... done
trying URL 'https://packagemanager.posit.co/cran/latest/src/contrib/vegan_2.6-4.tar.gz'
Content type 'binary/octet-stream' length 1490861 bytes (1.4 MB)
==================================================
downloaded 1.4 MB
> Will install 1 package.
> Will download 2 packages with unknown size.
+ permute 0.9-7 [dl]
i Getting 1 pkg with unknown size
v Got permute 0.9-7 (x86_64-pc-linux-gnu-ubuntu-22.04) (219.60 kB)
v Downloaded 1 package (219.60 kB) in 2s
v Installed permute 0.9-7 (18ms)
v 7 deps: added 1, dld 1 (219.60 kB) [2.7s]
* installing *source* package 'vegan' ...
** package 'vegan' successfully unpacked and MD5 sums checked
** using non-staged installation
** libs
using C compiler: 'emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.47 (431685f05c67f0424c11473cc16798b9587bb536)'
using Fortran compiler: 'flang-new version 17.0.6 (https://github.com/r-wasm/llvm-project 49f8a443424a6111bc055f349c9bfad0aa619c22)'
emcc -DNDEBUG -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.3.3/build/include -I/opt/webr/R/build/R-4.3.3/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -fpic -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -std=gnu11 -c data2hill.c -o data2hill.o
/opt/flang/host/bin/flang-new -fPIC -O2 -c decorana.f -o decorana.o
emcc -DNDEBUG -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.3.3/build/include -I/opt/webr/R/build/R-4.3.3/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -fpic -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -std=gnu11 -c getF.c -o getF.o
emcc -DNDEBUG -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.3.3/build/include -I/opt/webr/R/build/R-4.3.3/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -fpic -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -std=gnu11 -c goffactor.c -o goffactor.o
emcc -DNDEBUG -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.3.3/build/include -I/opt/webr/R/build/R-4.3.3/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -fpic -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -std=gnu11 -c init.c -o init.o
/opt/flang/host/bin/flang-new -fPIC -O2 -c monoMDS.f -o monoMDS.o
emcc -DNDEBUG -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.3.3/build/include -I/opt/webr/R/build/R-4.3.3/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -fpic -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -std=gnu11 -c nestedness.c -o nestedness.o
/opt/flang/host/bin/flang-new -fPIC -O2 -c ordering.f -o ordering.o
emcc -DNDEBUG -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.3.3/build/include -I/opt/webr/R/build/R-4.3.3/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -fpic -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -std=gnu11 -c pnpoly.c -o pnpoly.o
emcc -DNDEBUG -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.3.3/build/include -I/opt/webr/R/build/R-4.3.3/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -fpic -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -std=gnu11 -c stepacross.c -o stepacross.o
emcc -DNDEBUG -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.3.3/build/include -I/opt/webr/R/build/R-4.3.3/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -fpic -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -std=gnu11 -c vegdist.c -o vegdist.o
emcc -s SIDE_MODULE=1 -s WASM_BIGINT -s ASSERTIONS=1 -L/opt/webr/wasm/lib -L/opt/webr/wasm/R-4.3.3/lib/R/lib -s USE_BZIP2=1 -s USE_ZLIB=1 -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -Oz -o vegan.so data2hill.o decorana.o getF.o goffactor.o init.o monoMDS.o nestedness.o ordering.o pnpoly.o stepacross.o vegdist.o -L/lib/R/lib -lRlapack -L/lib/R/lib -lRblas /opt/flang/wasm/lib/libFortranRuntime.a
wasm-ld: error: function signature mismatch: malloc
>>> defined as (i64) -> i32 in monoMDS.o
>>> defined as (i32) -> i32 in /opt/flang/wasm/lib/libFortranRuntime.a(ISO_Fortran_binding.o)
emcc: error: '/opt/emsdk/upstream/bin/wasm-ld -o vegan.so --whole-archive -L/opt/webr/wasm/lib -L/opt/webr/wasm/R-4.3.3/lib/R/lib data2hill.o decorana.o getF.o goffactor.o init.o monoMDS.o nestedness.o ordering.o pnpoly.o stepacross.o vegdist.o -L/lib/R/lib /opt/webr/wasm/R-4.3.3/lib/R/lib/libRlapack.so -L/lib/R/lib /opt/webr/wasm/R-4.3.3/lib/R/lib/libRblas.so /opt/flang/wasm/lib/libFortranRuntime.a -L/opt/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr -mllvm -wasm-enable-eh -mllvm -exception-model=wasm --import-memory --strip-debug --export-dynamic --export-if-defined=main --export-if-defined=__get_exception_message --export-if-defined=free --export-if-defined=__cpp_exception --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=__thrown_object_from_unwind_exception --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=__wasm_apply_data_relocs --export-if-defined=fflush --export=__wasm_call_ctors --experimental-pic -shared' failed (returned 1)
make: *** [/opt/R/4.3.2/lib/R/share/make/shlib.mk:10: vegan.so] Error 1
ERROR: compilation failed for package 'vegan'
* removing '/tmp/RtmpyRTq6H/file19f246e3/vegan'
Error in wasm_build(pkg, tarball_path, out_dir) :
Building wasm binary for package 'vegan' failed. |
@isbool : thanks for the log. This seems to show the problem. However, I have no idea yet how to solve the problem. The error occurs in My first feeling is that we do nothing wrong, but the problem is in the 32-bit Fortran runtime in wasm instead of the 64 bit runtime. Compilation works, and |
There are other Fortran files in vegan which give no problem, but in Here a 141: INTEGER, ALLOCATABLE :: IWORK(:)
142: DOUBLE PRECISION, ALLOCATABLE :: GRAD(:,:), GRLAST(:,:)
151: ALLOCATE (IWORK(NDIS), GRAD(NOBJ,NDIM), GRLAST(NOBJ,NDIM))
359: DEALLOCATE (IWORK, GRAD, GRLAST) |
Jari,
I'll take a look at this code today.
Peter
Sent from my Verizon, Samsung Galaxy smartphone
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Jari Oksanen ***@***.***>
Sent: Wednesday, March 6, 2024 8:19:35 AM
To: vegandevs/vegan ***@***.***>
Cc: Minchin, Peter ***@***.***>; Mention ***@***.***>
Subject: Re: [vegandevs/vegan] Vegan for webR / wasm (Issue #623)
You don't often get email from ***@***.*** Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
There are other Fortran files in vegan which give no problem, but in monoMDS.f we allocate dynamically integer and double precision vectors. The log messages indicate (i64) -> i32 change in monoMDS.o, but then we get wasm-ld: error: function signature mismatch: malloc – so malloc may think differently of the types.
Here a grep of lines (with their numbers) dealing with dynamic allocation in the Fortran file monoMDS.f:
141: INTEGER, ALLOCATABLE :: IWORK(:)
142: DOUBLE PRECISION, ALLOCATABLE :: GRAD(:,:), GRLAST(:,:)
151: ALLOCATE (IWORK(NDIS), GRAD(NOBJ,NDIM), GRLAST(NOBJ,NDIM))
359: DEALLOCATE (IWORK, GRAD, GRLAST)
—
Reply to this email directly, view it on GitHub<#623 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AQBVAYIZHLOHZUJWN57NBJLYW4QXPAVCNFSM6AAAAABEFGXLVKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBQHE3TMMBYGQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@prminchin After more googling, I think it is a problem with the wasm build tools. It's possible that we could do something for this problem at the cost of ruining all other cases. This wasm is a Java application where you can run code in another computer in your own computer. Looking at this case, wasm people are worried that Fortran uses 64-bit integers instead of 32-bit integers, but we should be worried about using 32-bit integers. Let's see what kind of response we get, but certainly we will not downgrade code to accomodate wasm. |
Jari,
I can’t see anything wrong with the code but it’s possible that the compiler expects the all the arrays in the list in ALLOCATE to be of the same type (though I can’t find any documentation of this). One thing to try then would be to use separate ALLOCATE statements for IWORK and the two double precision arrays:
ALLOCATE (IWORK(NDIS))
ALLOCATE (GRAD(NOBJ,NDIM), GRLAST(NOBJ,NDIM))
I traced the use of IWORK in monoMDS. It’s only used in MONREG and is declared there as INTEGER, the same as in monoMDS.
Just got your more recent e-mail about wasm, with which I am not familiar. Maybe wasm is not following the FORTRAN 95 standard in allocatable array handling.
Peter
Peter Minchin
301 Camellia Dr
Corpus Christi, TX 78404
USA
Phone: +1-618-521-5616
From: Jari Oksanen ***@***.***>
Sent: Wednesday, March 6, 2024 8:20 AM
To: vegandevs/vegan ***@***.***>
Cc: Minchin, Peter ***@***.***>; Mention ***@***.***>
Subject: Re: [vegandevs/vegan] Vegan for webR / wasm (Issue #623)
You don't often get email from ***@***.******@***.***>. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
There are other Fortran files in vegan which give no problem, but in monoMDS.f we allocate dynamically integer and double precision vectors. The log messages indicate (i64) -> i32 change in monoMDS.o, but then we get wasm-ld: error: function signature mismatch: malloc – so malloc may think differently of the types.
Here a grep of lines (with their numbers) dealing with dynamic allocation in the Fortran file monoMDS.f:
141: INTEGER, ALLOCATABLE :: IWORK(:)
142: DOUBLE PRECISION, ALLOCATABLE :: GRAD(:,:), GRLAST(:,:)
151: ALLOCATE (IWORK(NDIS), GRAD(NOBJ,NDIM), GRLAST(NOBJ,NDIM))
359: DEALLOCATE (IWORK, GRAD, GRLAST)
—
Reply to this email directly, view it on GitHub<#623 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AQBVAYIZHLOHZUJWN57NBJLYW4QXPAVCNFSM6AAAAABEFGXLVKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBQHE3TMMBYGQ>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
would it be possible for me to exclude this file and lose only some functionality, to be able to use the rest of vegan on wasm? |
@isbool you can always maintain your own version of vegan, just fork the repo, remove what you want (and make sure it passes That said, |
Like @gavinsimpson wrote, Here some things you need to do (just out of memory without looking at the package):
|
I will attempt to do that, but its seems monoMDS and metaMDS are rooted deeply into vegan. Is there any chance that you might look into how possible is to actually figure out the issue exactly and the options to solve it ? Also could i somehow force the compiler to compile to i32 integers to match wasm ? Is there any chance building webR with Dragonegg as mention here can have help some how fix this? |
This is a known bug in our fork of the LLVM @jarioksa is right; the issue is that dynamic allocation with I'm investigating, but I don't yet have a strong idea of when a fix will be available. This is not the only R package affected. It is highly likely there is nothing wrong with the code in this package, especially if it compiles fine on other systems. I would recommend waiting until support for |
@georgestagg @prminchin @isbool – Before inspecting the code (what a blessing!) I think it may be possible to change the code so that it does not use dynamic allocation (ALLOCATE in Fortran, seemingly cascading to malloc in C). In principle – in practice it may be hard work. The Fortran code is derived from a main program where dynamic allocation is necessary, but we are using it as a subroutine which means that we could reserve the storage in the calling routine and pass the arrays from the calling program. This is not something that a Real Programmer would like to do for internal work arrays that are not needed in the calling program, but it could solve the issue while the LLVM flang is not yet fixed. @georgestagg : we got this error message for an INTEGER array, but we also have two DOUBLE PRECISION (like it used to be called way back when I wrote Fortran) arrays. We did not get any errors from those, but is this only because the build stopped with the first error? |
@isbool: @prminchin sent me a revised version of |
Hey, how its going? any unexpected hiccups ? |
With all due respect; it's the weekend, and no one here is paid to work on vegan. Sit tight and I'm sure someone will update the thread if progress is made. |
yea yea no pressure i just asked, if there was something i could do to help, no pressure |
Vegan could not be built for webR/wasm because their Fortran compiler (under development) did not handle dynamic allocation. This needed some hand-editing as the fix was not based on the latest github version and contained removed subroutines.
Commit 75e347d removes dynamic allocation, and if that was the only problem, vegan should work with webR / wasm. |
Can anybody confirm that vegan can be built in webR / wasm? I don't have tools to test this. |
Thanks! Closing this as completed. |
Hey,
Would it be possible for vegan to be compiled to emscripten to be able to be used with webR / wasm.
The text was updated successfully, but these errors were encountered: