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

flang-new not working on tutorial #3

Open
jarrodcolburn opened this issue Oct 19, 2024 · 3 comments
Open

flang-new not working on tutorial #3

jarrodcolburn opened this issue Oct 19, 2024 · 3 comments

Comments

@jarrodcolburn
Copy link

Trying to follow along with article, https://gws.phd/posts/fortran_wasm/

thanks, btw. amazing work!

when trying to build lapack-3.12.0 running

make lib

I get the following error:

make -C SRC
make[1]: Entering directory '/root/lapack_example/lapack-3.12.0/SRC'
flang-new -O2   -c -o sbdsvdx.o sbdsvdx.f
flang-new -O2   -c -o spotrf2.o spotrf2.f
flang-new -O2   -c -o sgetrf2.o sgetrf2.f
flang-new -O2   -c -o sgbbrd.o sgbbrd.f
flang-new -O2   -c -o sgbcon.o sgbcon.f
....
flang-new -O2   -c -o ssbev_2stage.o ssbev_2stage.f
flang-new -O2   -c -o ssbevx_2stage.o ssbevx_2stage.f
flang-new -O2   -c -o ssbevd_2stage.o ssbevd_2stage.f
flang-new -O2   -c -o ssygv_2stage.o ssygv_2stage.f
flang-new -O2   -c -o sgesvdq.o sgesvdq.f
flang-new -O2  -c -o la_constants.o la_constants.f90
./la_constants.f90:65:37: warning: overflow on power with INTEGER exponent
     real(sp), parameter :: ssafmin = real(radix(0._sp),sp)**max( &
                                      ^
./la_constants.f90:82:35: warning: overflow on power with INTEGER exponent
     real(sp), parameter :: sssml = real(radix(0._sp), sp)**( - floor( &
                                    ^
./la_constants.f90:85:35: warning: overflow on power with INTEGER exponent
     real(sp), parameter :: ssbig = real(radix(0._sp), sp)**( - ceiling( &
                                    ^
./la_constants.f90:108:37: warning: overflow on power with INTEGER exponent
     real(dp), parameter :: dsafmin = real(radix(0._dp),dp)**max( &
                                      ^
./la_constants.f90:125:35: warning: overflow on power with INTEGER exponent
     real(dp), parameter :: dssml = real(radix(0._dp), dp)**( - floor( &
                                    ^
./la_constants.f90:128:35: warning: overflow on power with INTEGER exponent
     real(dp), parameter :: dsbig = real(radix(0._dp), dp)**( - ceiling( &
                                    ^
flang-new -O2  -c -o la_xisnan.o la_xisnan.F90
flang-new -O2  -c -o sgedmd.o sgedmd.f90
error: Semantic errors in sgedmd.f90
./sgedmd.f90:543:29: error: Cannot read module file for module 'iso_fortran_env': Source file 'iso_fortran_env.mod' was not found
        USE                   iso_fortran_env
                              ^^^^^^^^^^^^^^^
./sgedmd.f90:545:34: error: No explicit type declared for 'real32'
        INTEGER, PARAMETER :: WP = real32
                                   ^^^^^^
./sgedmd.f90:645:19: error: 'tol' is not an object that can appear in an expression
        ELSE IF ( ( TOL < ZERO ) .OR. ( TOL >= ONE ) )  THEN
                    ^^^
./sgedmd.f90:554:37: Declaration of 'tol'
        REAL(KIND=WP), INTENT(IN) ::  TOL
                                      ^^^
./sgedmd.f90:645:25: error: 'zero' is not an object that can appear in an expression
        ELSE IF ( ( TOL < ZERO ) .OR. ( TOL >= ONE ) )  THEN
                          ^^^^
./sgedmd.f90:569:35: Declaration of 'zero'
        REAL(KIND=WP), PARAMETER :: ZERO = 0.0_WP
                                    ^^^^
./sgedmd.f90:645:46: error: 'one' is not an object that can appear in an expression
        ELSE IF ( ( TOL < ZERO ) .OR. ( TOL >= ONE ) )  THEN
                                               ^^^
./sgedmd.f90:568:36: Declaration of 'one'
        REAL(KIND=WP), PARAMETER ::  ONE = 1.0_WP
                                     ^^^
./sgedmd.f90:669:17: error: 'work' is not an object that can appear in an expression
                  WORK(1)  = 2
                  ^^^^
./sgedmd.f90:563:39: Declaration of 'work'
        REAL(KIND=WP), INTENT(OUT)   :: WORK(*)
                                        ^^^^
./sgedmd.f90:688:46: error: 'x' is not an object that can appear in an expression
                  CALL SGESVD( 'O', 'S', M, N, X, LDX, WORK, &
                                               ^
./sgedmd.f90:558:39: Declaration of 'x'
        REAL(KIND=WP), INTENT(INOUT) :: X(LDX,*), Y(LDY,*)
                                        ^
./sgedmd.f90:689:28: error: 'b' is not an object that can appear in an expression
                             B, LDB, W, LDW, RDUMMY, -1, INFO1 )
                             ^
./sgedmd.f90:559:49: Declaration of 'b'
        REAL(KIND=WP), INTENT(OUT)   :: Z(LDZ,*), B(LDB,*), &
                                                  ^
./sgedmd.f90:689:36: error: 'w' is not an object that can appear in an expression
                             B, LDB, W, LDW, RDUMMY, -1, INFO1 )
                                     ^
./sgedmd.f90:560:39: Declaration of 'w'
                                        W(LDW,*), S(LDS,*)
                                        ^
./sgedmd.f90:689:44: error: 'rdummy' is not an object that can appear in an expression
                             B, LDB, W, LDW, RDUMMY, -1, INFO1 )
                                             ^^^^^^
./sgedmd.f90:587:33: Declaration of 'rdummy'
        REAL(KIND=WP) :: AB(2,2), RDUMMY(2), RDUMMY2(2)
                                  ^^^^^^
./sgedmd.f90:717:41: error: 'z' is not an object that can appear in an expression
                            X, LDX, WORK, Z, LDZ, W, LDW,   &
                                          ^
./sgedmd.f90:559:39: Declaration of 'z'
        REAL(KIND=WP), INTENT(OUT)   :: Z(LDZ,*), B(LDB,*), &
                                        ^
./sgedmd.f90:719:34: error: 'rdummy2' is not an object that can appear in an expression
                               -1, RDUMMY2, -1, INFO1 )
                                   ^^^^^^^
./sgedmd.f90:587:44: Declaration of 'rdummy2'
        REAL(KIND=WP) :: AB(2,2), RDUMMY(2), RDUMMY2(2)
                                             ^^^^^^^
./sgedmd.f90:750:44: error: 's' is not an object that can appear in an expression
                  CALL SGEEV( 'N', JOBZL, N, S, LDS, REIG, &
                                             ^
./sgedmd.f90:560:49: Declaration of 's'
                                        W(LDW,*), S(LDS,*)
                                                  ^
./sgedmd.f90:750:52: error: 'reig' is not an object that can appear in an expression
                  CALL SGEEV( 'N', JOBZL, N, S, LDS, REIG, &
                                                     ^^^^
./sgedmd.f90:561:39: Declaration of 'reig'
        REAL(KIND=WP), INTENT(OUT)   :: REIG(*),  IMEIG(*), &
                                        ^^^^
./sgedmd.f90:751:21: error: 'imeig' is not an object that can appear in an expression
                      IMEIG, W, LDW, W, LDW, RDUMMY, -1, INFO1 )
                      ^^^^^
./sgedmd.f90:561:49: Declaration of 'imeig'
        REAL(KIND=WP), INTENT(OUT)   :: REIG(*),  IMEIG(*), &
                                                  ^^^^^
./sgedmd.f90:772:7: error: 'ofl' is not an object that can appear in an expression
        OFL   = SLAMCH('O')
        ^^^
./sgedmd.f90:573:24: Declaration of 'ofl'
        REAL(KIND=WP) :: OFL,   ROOTSC, SCALE,  SMALL,   &
                         ^^^
./sgedmd.f90:773:7: error: 'small' is not an object that can appear in an expression
        SMALL = SLAMCH('S')
        ^^^^^
./sgedmd.f90:573:47: Declaration of 'small'
        REAL(KIND=WP) :: OFL,   ROOTSC, SCALE,  SMALL,   &
                                                ^^^^^
./sgedmd.f90:785:13: error: 'scale' is not an object that can appear in an expression
              SCALE  = ZERO
              ^^^^^
./sgedmd.f90:573:39: Declaration of 'scale'
        REAL(KIND=WP) :: OFL,   ROOTSC, SCALE,  SMALL,   &
                                        ^^^^^
./sgedmd.f90:786:47: error: 'ssum' is not an object that can appear in an expression
              CALL SLASSQ( M, X(1,i), 1, SCALE, SSUM )
                                                ^^^^
./sgedmd.f90:574:24: Declaration of 'ssum'
                         SSUM,  XSCL1,  XSCL2
                         ^^^^
./sgedmd.f90:793:16: error: 'rootsc' is not an object that can appear in an expression
                 ROOTSC = SQRT(SSUM)
                 ^^^^^^
./sgedmd.f90:573:31: Declaration of 'rootsc'
        REAL(KIND=WP) :: OFL,   ROOTSC, SCALE,  SMALL,   &
                                ^^^^^^
./sgedmd.f90:831:45: error: 'y' is not an object that can appear in an expression
                  CALL SSCAL( M, ONE/WORK(i), Y(1,i), 1 )  ! BLAS CALL
                                              ^
./sgedmd.f90:558:49: Declaration of 'y'
        REAL(KIND=WP), INTENT(INOUT) :: X(LDX,*), Y(LDY,*)
                                                  ^
./sgedmd.f90:940:15: error: 'xscl1' is not an object that can appear in an expression
                XSCL1 = WORK(N+1)
                ^^^^^
./sgedmd.f90:574:31: Declaration of 'xscl1'
                         SSUM,  XSCL1,  XSCL2
                                ^^^^^
./sgedmd.f90:941:15: error: 'xscl2' is not an object that can appear in an expression
                XSCL2 = WORK(N+2)
                ^^^^^
./sgedmd.f90:574:39: Declaration of 'xscl2'
                         SSUM,  XSCL1,  XSCL2
                                        ^^^^^
./sgedmd.f90:1161:17: error: 'res' is not an object that can appear in an expression
                  RES(i) = SNRM2( M, Y(1,i), 1 )                         ! BLAS CALL
                  ^^^
./sgedmd.f90:562:39: Declaration of 'res'
                                        RES(*)
                                        ^^^
./sgedmd.f90:1171:16: error: 'ab' is not an object that can appear in an expression
                 AB(1,1) =  REIG(i)
                 ^^
./sgedmd.f90:587:24: Declaration of 'ab'
        REAL(KIND=WP) :: AB(2,2), RDUMMY(2), RDUMMY2(2)
                         ^^
make[1]: *** [Makefile:66: sgedmd.o] Error 1
rm la_xisnan.mod
make[1]: Leaving directory '/root/lapack_example/lapack-3.12.0/SRC'
make: *** [Makefile:25: lapacklib] Error 2

I made the needed changes to make.inc as described.

@georgestagg
Copy link
Member

Hi, it looks like the fileiso_fortran_env.mod is missing or can't be found. Are you following along from scratch or using the Docker container image?

If you are following along from scratch, the file should have been built by LLVM and exist at the path [...]/build/include/flang/iso_fortran_env.mod. Does that path and file exist?

If you are using the docker container, the module has probably just not been added to the container image. We can fix that if so, just let me know.

@jarrodcolburn
Copy link
Author

jarrodcolburn commented Oct 21, 2024

I'm using the docker container (and it's prebuilt binary).

btw, I'm not familiar with .mod (or patched files) . In the tutorial I see .mod files...
ieee_arithmetic.mod produced by patch -p1 -d llvm-project < add-wasm32-target.diff
ieee_arithmetic.f18.mod produced by patch -p1 -d llvm-project < force-4-byte-values.diff

is iso_fortran_env.mod a new patch?

@georgestagg
Copy link
Member

The .mod files are Fortran module interface files, they're needed to use a compiled Fortran module from another file. Several are created when compiling LLVM and the Fortran runtime.

The flang-new binary was copied to the Docker container, but not the .mod files. I missed it because I've been working with the native compiled from scratch version, my apologies!

I've pushed an update to the Docker image to include the missing files, so the process to compile lapack should look something like this:

First, pull and start the latest image:

docker pull ghcr.io/r-wasm/flang-wasm:main
docker run -it --rm ghcr.io/r-wasm/flang-wasm:main

Setup the environment for Emscripten, install vim or some other editor,

cd
. /opt/emsdk/emsdk_env.sh
apt update && apt install -y vim

Download and prepare lapack:

curl -L https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.12.0.tar.gz > lapack-3.12.0.tgz
tar xzf lapack-3.12.0.tgz
cp lapack-3.12.0/make.inc.example lapack-3.12.0/make.inc
vim lapack-3.12.0/make.inc
# [...Prepare make.inc as described in the blog post, with /opt/flang/host/bin/flang-new...]

Build lapack:

cd lapack-3.12.0
make lib
ls liblapack.a 
# liblapack.a

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