Skip to content
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

WASM support #7

Open
andrjohns opened this issue Jan 2, 2024 · 9 comments
Open

WASM support #7

andrjohns opened this issue Jan 2, 2024 · 9 comments

Comments

@andrjohns
Copy link
Owner

Package fails to compile due to TBB architecture/machine detection issues, investigate appropriate TBB macros for WASM:

/** This header provides basic platform abstraction layer by hooking up appropriate
    architecture/OS/compiler specific headers from the /include/tbb/machine directory.
    If a plug-in header does not implement all the required APIs, it must specify
    the missing ones by setting one or more of the following macros:

    __TBB_USE_GENERIC_PART_WORD_CAS
    __TBB_USE_GENERIC_PART_WORD_FETCH_ADD
    __TBB_USE_GENERIC_PART_WORD_FETCH_STORE
    __TBB_USE_GENERIC_FETCH_ADD
    __TBB_USE_GENERIC_FETCH_STORE
    __TBB_USE_GENERIC_DWORD_FETCH_ADD
    __TBB_USE_GENERIC_DWORD_FETCH_STORE
    __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE
    __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE
    __TBB_USE_GENERIC_RELAXED_LOAD_STORE
    __TBB_USE_FETCHSTORE_AS_FULL_FENCED_STORE
**/
@andrjohns
Copy link
Owner Author

Fixed in main

@StaffanBetner
Copy link

But the package isn't loadable in webR:

> install.packages('StanEstimators',
  repos = c('https://andrjohns.r-universe.dev', 'https://repo.r-wasm.org'))
Downloading webR package: Rcpp
Downloading webR package: RcppParallel
Downloading webR package: abind
Downloading webR package: backports
Downloading webR package: checkmate
Downloading webR package: rlang
Downloading webR package: fansi
Downloading webR package: cli
Downloading webR package: glue
Downloading webR package: lifecycle
Downloading webR package: magrittr
Downloading webR package: utf8
Downloading webR package: vctrs
Downloading webR package: pillar
Downloading webR package: pkgconfig
Downloading webR package: tibble
Downloading webR package: tensorA
Downloading webR package: generics
Downloading webR package: numDeriv
Downloading webR package: gtable
Downloading webR package: isoband
Downloading webR package: MASS
Downloading webR package: lattice
Downloading webR package: nlme
Downloading webR package: Matrix
Downloading webR package: mgcv
Downloading webR package: farver
Downloading webR package: labeling
Downloading webR package: colorspace
Downloading webR package: munsell
Downloading webR package: R6
Downloading webR package: RColorBrewer
Downloading webR package: viridisLite
Downloading webR package: scales
Downloading webR package: withr
Downloading webR package: ggplot2
Downloading webR package: digest
Downloading webR package: distributional
Downloading webR package: matrixStats
Downloading webR package: posterior
Downloading webR package: ps
Downloading webR package: processx
Downloading webR package: callr
Downloading webR package: codetools
Downloading webR package: globals
Downloading webR package: listenv
Downloading webR package: parallelly
Downloading webR package: future
Downloading webR package: RcppEigen
Downloading webR package: BH
Downloading webR package: rapidjsonr
Downloading webR package: StanEstimators
> library(StanEstimators)
Error: package or namespace load failed for ‘StanEstimators’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/lib/R/library/StanEstimators/libs/StanEstimators.so':
  Could not load dynamic lib: /usr/lib/R/library/StanEstimators/libs/StanEstimators.so
Error: bad export type for '_ZTIN3tbb4taskE': undefined

@andrjohns
Copy link
Owner Author

Ah that's what I get for not testing. What's the easiest way for me to iterate with webR? Do you use the demo web REPL or run something else locally?

@andrjohns andrjohns reopened this Jan 3, 2024
@StaffanBetner
Copy link

I use the demo web REPL.

@andrjohns
Copy link
Owner Author

Ah, it looks like this will be a tricky one to get working. The Math library needs to link to the TBB (not just include it's headers). To do this under WASM, the TBB itself needs to be built with emscripten so that the library is in a format that it can be linked to. However, when installing/building RcppParallel for webR, the TBB itself does not get built - so there is nothing for StanEstimators to link to during installation.

I'll open an issue on the r-universe or r-wasm repo, but I don't expect this to be workable anytime too soon

@StaffanBetner
Copy link

Related? RcppCore/RcppParallel#88

@andrjohns
Copy link
Owner Author

Possibly. But compiling the TBB under emscripten is beyond the scope of what I can patch/fix in this package and likely to need a fairly non-trivial amount of work, so I'm not likely to tackle it any time soon unfortunately

@StaffanBetner
Copy link

No worries, it is more fun to have, rather than need to have. :)

@StaffanBetner
Copy link

Just a note, the main issue is this one: r-wasm/webr#427

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants