Skip to content

swapped real and imaginary parts of extended complex xdotu and xdotc results #768

Closed

Description

@venovako

Hi,

Please, could you check if the extended complex dot-product functions xdotu and xdotc produce their results with the real and imaginary parts swapped?

Here is a test code (Fortran 90, gfortran 5.2 on MacOS 10.11.3), to be linked with OpenBLAS:

program qxtest

  implicit none

  integer, parameter :: n = 2, incx = 1, incy = 1

  complex(8) :: zx(n), zy(n), zc, zu
  complex(10) :: xx(n), xy(n), xc, xu

  complex(8), external :: zdotc, zdotu
  complex(10), external :: xdotc, xdotu

  zx(1) = ( 1e0_8, -1e0_8)
  zx(2) = (-3e0_8,  3e0_8)
  zy(1) = ( 2e0_8, -2e0_8)
  zy(2) = ( 4e0_8, -4e0_8)

  xx(1) = ( 1e0_10, -1e0_10)
  xx(2) = (-3e0_10,  3e0_10)
  xy(1) = ( 2e0_10, -2e0_10)
  xy(2) = ( 4e0_10, -4e0_10)

  zc = zdotc(n, zx, incx, zy, incy)
  print *, 'dotc(KIND= 8) =', zc
  xc = xdotc(n, xx, incx, xy, incy)
  print *, 'dotc(KIND=10) =', xc

  zu = zdotu(n, zx, incx, zy, incy)
  print *, 'dotu(KIND= 8) =', zu
  xu = xdotu(n, xx, incx, xy, incy)
  print *, 'dotu(KIND=10) =', xu

end program qxtest

And the output is:

 dotc(KIND= 8) = ( -20.000000000000000     ,  0.0000000000000000     )
 dotc(KIND=10) = (  0.00000000000000000000      , -20.0000000000000000000      )
 dotu(KIND= 8) = (  0.0000000000000000     ,  20.000000000000000     )
 dotu(KIND=10) = (  20.0000000000000000000      ,  0.00000000000000000000      )

So, double precision functions return the correct results, but the extended precision ones do not.

Activity

  1. brada4 commented on Jan 31, 2016

    @brada4
    Contributor

    how did you build openblas to have x* functions exported? normally they are not.

  2. zerothi commented on Jan 31, 2016

    @zerothi

    Are you sure it is the correct kind, if I remember correctly gcc provides 2
    kinds of same bit length.
    I am not at my box but run through kinds to check which it actually is.

    Kind regards Nick Papior
    On 31 Jan 2016 02:51, "brada4" notifications@github.com wrote:

    how did you build openblas to have x* functions exported? normally they
    are not.

    —
    Reply to this email directly or view it on GitHub
    #768 (comment).

  3. venovako commented on Jan 31, 2016

    @venovako
    Author

    @brada4:

    I build from the latest GitHub sources.
    Here's my Makefile.rule:

    #
    #  Beginning of user configuration
    #
    
    # This library's version
    VERSION = 0.2.16.dev
    
    # If you set the suffix, the library name will be libopenblas_$(LIBNAMESUFFIX).a
    # and libopenblas_$(LIBNAMESUFFIX).so. Meanwhile, the soname in shared library
    # is libopenblas_$(LIBNAMESUFFIX).so.0.
    # LIBNAMESUFFIX = omp
    
    # You can specify the target architecture, otherwise it's
    # automatically detected.
    TARGET = HASWELL
    
    # If you want to support multiple architecture in one binary
    # DYNAMIC_ARCH = 1
    
    # C compiler including binary type(32bit / 64bit). Default is gcc.
    # Don't use Intel Compiler or PGI, it won't generate right codes as I expect.
    CC = clang -ffp-contract=on -integrated-as
    
    # Fortran compiler. Default is g77.
    FC = gfortran -Wa,-q -Wl,-no_compact_unwind
    
    # Even you can specify cross compiler. Meanwhile, please set HOSTCC.
    
    # cross compiler for Windows
    # CC = x86_64-w64-mingw32-gcc
    # FC = x86_64-w64-mingw32-gfortran
    
    # cross compiler for 32bit ARM
    # CC = arm-linux-gnueabihf-gcc
    # FC = arm-linux-gnueabihf-gfortran
    
    # cross compiler for 64bit ARM
    # CC = aarch64-linux-gnu-gcc
    # FC = aarch64-linux-gnu-gfortran
    
    
    # If you use the cross compiler, please set this host compiler.
    # HOSTCC = gcc
    
    # If you need 32bit binary, define BINARY=32, otherwise define BINARY=64
    BINARY=64
    
    # About threaded BLAS. It will be automatically detected if you don't
    # specify it.
    # For force setting for single threaded, specify USE_THREAD = 0
    # For force setting for multi  threaded, specify USE_THREAD = 1
    USE_THREAD = 1
    
    # If you're going to use this library with OpenMP, please comment it in.
    # USE_OPENMP = 1
    
    # You can define maximum number of threads. Basically it should be
    # less than actual number of cores. If you don't specify one, it's
    # automatically detected by the the script.
    # NUM_THREADS = 4
    
    # if you don't need to install the static library, please comment it in.
    # NO_STATIC = 1
    
    # if you don't need generate the shared library, please comment it in.
    # NO_SHARED = 1
    
    # If you don't need CBLAS interface, please comment it in.
    NO_CBLAS = 1
    
    # If you only want CBLAS interface without installing Fortran compiler,
    # please comment it in.
    # ONLY_CBLAS = 1
    
    # If you don't need LAPACK, please comment it in.
    # If you set NO_LAPACK=1, the library automatically sets NO_LAPACKE=1.
    NO_LAPACK = 1
    
    # If you don't need LAPACKE (C Interface to LAPACK), please comment it in.
    # NO_LAPACKE = 1
    
    # If you want to use legacy threaded Level 3 implementation.
    # USE_SIMPLE_THREADED_LEVEL3 = 1
    
    # If you want to drive whole 64bit region by BLAS. Not all Fortran
    # compiler supports this. It's safe to keep comment it out if you
    # are not sure(equivalent to "-i8" option).
    # INTERFACE64 = 1
    
    # Unfortunately most of kernel won't give us high quality buffer.
    # BLAS tries to find the best region before entering main function,
    # but it will consume time. If you don't like it, you can disable one.
    NO_WARMUP = 1
    
    # If you want to disable CPU/Memory affinity on Linux.
    NO_AFFINITY = 1
    
    # if you are compiling for Linux and you have more than 16 numa nodes or more than 256 cpus
    # BIGNUMA = 1
    
    # Don't use AVX kernel on Sandy Bridge. It is compatible with old compilers
    # and OS. However, the performance is low.
    # NO_AVX = 1
    
    # Don't use Haswell optimizations if binutils is too old (e.g. RHEL6)
    # NO_AVX2 = 1
    
    # Don't use parallel make.
    # NO_PARALLEL_MAKE = 1
    
    # Force number of make jobs. The default is the number of logical CPU of the host.
    # This is particularly useful when using distcc
    # MAKE_NB_JOBS = 8
    
    # If you would like to know minute performance report of GotoBLAS.
    # FUNCTION_PROFILE = 1
    
    # Support for IEEE quad precision(it's *real* REAL*16)( under testing)
    # QUAD_PRECISION = 1
    
    # Theads are still working for a while after finishing BLAS operation
    # to reduce thread activate/deactivate overhead. You can determine
    # time out to improve performance. This number should be from 4 to 30
    # which corresponds to (1 << n) cycles. For example, if you set to 26,
    # thread will be running for (1 << 26) cycles(about 25ms on 3.0GHz
    # system). Also you can control this mumber by THREAD_TIMEOUT
    # CCOMMON_OPT   += -DTHREAD_TIMEOUT=26
    
    # Using special device driver for mapping physically contigous memory
    # to the user space. If bigphysarea is enabled, it will use it.
    # DEVICEDRIVER_ALLOCATION = 1
    
    # If you need to synchronize FP CSR between threads (for x86/x86_64 only).
    CONSISTENT_FPCSR = 1
    
    # If any gemm arguement m, n or k is less or equal this threshold, gemm will be execute
    # with single thread. You can use this flag to avoid the overhead of multi-threading
    # in small matrix sizes. The default value is 4.
    # GEMM_MULTITHREAD_THRESHOLD = 4
    
    # If you need santy check by comparing reference BLAS. It'll be very
    # slow (Not implemented yet).
    # SANITY_CHECK = 1
    
    # Run testcases in utest/ . When you enable UTEST_CHECK, it would enable
    # SANITY_CHECK to compare the result with reference BLAS.
    # UTEST_CHECK = 1
    
    # The installation directory.
    PREFIX = /usr/local
    
    # Common Optimization Flag;
    # The default -O2 is enough.
    COMMON_OPT = -O3 -fexceptions -march=native -pipe
    
    # gfortran option for LAPACK
    # enable this flag only on 64bit Linux and if you need a thread safe lapack library
    FCOMMON_OPT = -frecursive
    
    # Profiling flags
    COMMON_PROF = -pg
    
    # Build Debug version
    # DEBUG = 1
    
    
    # Set maximum stack allocation.
    # The default value is 2048. 0 disable stack allocation a may reduce GER and GEMV
    # performance. For details, https://github.com/xianyi/OpenBLAS/pull/482
    #
    # MAX_STACK_ALLOC = 0
    
    # Add a prefix or suffix to all exported symbol names in the shared library.
    # Avoid conflicts with other BLAS libraries, especially when using
    # 64 bit integer interfaces in OpenBLAS.
    # For details, https://github.com/xianyi/OpenBLAS/pull/459
    #
    # The same prefix and suffix are also added to the library name,
    # i.e. you get lib$(SYMBOLPREFIX)openblas$(SYMBOLSUFFIX) rather than libopenblas
    #
    # SYMBOLPREFIX=
    # SYMBOLSUFFIX=
    
    #
    #  End of user configuration
    #
    

    @zerothi:

    I'm reasonably sure it is the correct kind, please see:

    program zxkind
    
      implicit none
    
      complex(10) :: a
      real(10) :: b(2)
      equivalence (a,b(1))
    
      a = (1e0_10, 2e0_10)
    
      print *, 'sizeof(real(10))    =', sizeof(b(1))
      print *, 'sizeof(complex(10)) =', sizeof(a)
      print *, 'first component     =', b(1)
      print *, 'second component    =', b(2)
    
    end program zxkind

    The output (gfortran 5.2, MacOS):

     sizeof(real(10))    =                   16
     sizeof(complex(10)) =                   32
     first component     =   1.00000000000000000000      
     second component    =   2.00000000000000000000      
    

    Sizeof real extended is 16 bytes (10 bytes + padding), sizeof complex extended is twice that, and the first 16 bytes of a complex variable represents its real part, the last 16 bytes its imaginary part.

  4. brada4 commented on Jan 31, 2016

    @brada4
    Contributor

    x* functions are not present in current version. They were in gotoblas, but probably never worked at all, nor there is any standard behaviour defined for them...
    can you quickly check with
    nm -B libopenblas.dylib (should have no xdotu)
    ldd your_testcase (does it really link to the right openblas, or you have some old version around)

  5. martin-frbg commented on Jan 31, 2016

    @martin-frbg
    Collaborator

    From the NO_LAPACK in your Makefile.rule I suspect you are linking to a netlib(-derived) LAPACK that may have been built with USE_XBLAS, pulling in netlib xblas (libxblas) which is a separate project.

  6. venovako commented on Jan 31, 2016

    @venovako
    Author

    @brada4:

    nm -m libopenblas_haswell-r0.2.16.dev.dylib | grep xdot
    0000000000025010 (__TEXT,__text) external _xdotc_
    0000000000bf58e0 (__TEXT,__text) non-external (was a private external) _xdotc_k
    0000000000025060 (__TEXT,__text) external _xdotu_
    0000000000bf5a60 (__TEXT,__text) non-external (was a private external) _xdotu_k
    

    The initial example (qxtest) is built as:

    gfortran -O3 -fexceptions -frecursive -march=native -pipe -Wa,-q qxtest.f90 -L/usr/local/lib -lopenblas
    

    (Using the same compiler flags as for the library itself.)
    And yes, I link to this version (symlinked as libopenblas.dylib):

    $ ls -la /usr/local/lib/libopenblas.dylib 
    lrwxr-xr-x  1 root  admin  38 30 Jan 23:04 /usr/local/lib/libopenblas.dylib -> libopenblas_haswellp-r0.2.16.dev.dylib
    $ otool -L ./a.out 
    ./a.out:
        /usr/local/lib/libopenblas_haswellp-r0.2.16.dev.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/local/gfortran/lib/libgfortran.3.dylib (compatibility version 4.0.0, current version 4.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
        /usr/local/gfortran/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/local/gfortran/lib/libquadmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    

    (As you might have noticed, this is MacOS, not Linux.)

    @martin-frbg:
    In this example, I don't link to any LAPACK implementation whatsoever, and certainly not to Xblas, which I have never used.
    And I deliberately don't want to build LAPACK, CBLAS interface, etc. included in OpenBLAS.

    I have an unmodified, up-to-date repository of OpenBLAS, of which I make a copy, replace Makefile.rule with the one included above, and say "make" and "sudo make install".
    What I get is a library that most certainly contains the x* routines.
    I don't link to GotoBLAS, Xblas, or anything of the sort, as you may see above.

  7. martin-frbg commented on Jan 31, 2016

    @martin-frbg
    Collaborator

    Got it now - these functions are only built if EXPRECISION is defined, or conversely if NO_EXPRECISION is not set in Makefile.system. For all OSNAMEs except Darwin, AIX and the BSDs, NO_EXPRECISION is explicitly set in Makefile.system, so presumably only the latter are assumed to have proper system library support for the extended complex functions. (Given that there is an open ticket for updating the build system to support AIX, it seems doubtful that it has been tested on that platform at least in recent years. Perhaps the commit history of Makefile.system will reveal if the entries were actually adapted or just copied over from existing ones when new operating systems were added.)

  8. martin-frbg commented on Jan 31, 2016

    @martin-frbg
    Collaborator

    Haswell Linux build (after removing the NO_EXPRECISION) gives exact same result for the testcase as above. Most of the settings in Makefile.system appear to be unchanged from GotoBLAS2, but the NO_EXPRECISION entry for Linux was added by @wernsaar in May 2014 (a35a1a9) with a commit message reading just "changed makefiles for lapack development".

  9. martin-frbg commented on Jan 31, 2016

    @martin-frbg
    Collaborator

    Both xdotc and xdotu are compiled from kernel/x86_64/zdot.S (with -DCONJ for xdotc, -UCONJ for xdotu, -DCOMPLEX -DXDOUBLE for both), this file is unchanged from GotoBLAS2. Perhaps the single "#ifndef CONJ" before the regular return from the function simply needs to be inverted - no other function appears to be built from this assembler file ?
    Hmm. Not that simple - inverting the if clause gives the right absolute values but the wrong signs.
    And I know just enough assembler to be a nuisance, not even dangerous.

  10. brada4 commented on Jan 31, 2016

    @brada4
    Contributor

    Is it float(10) or float(12) or float(16) (looking around #ifdefs)
    https://www.freebsd.org/cgi/man.cgi?query=ieee

  11. venovako commented on Feb 1, 2016

    @venovako
    Author

    @martin-frbg:

    Thanks for looking into that!
    I'm not versed in x87 assembler, either.
    If there's no one still maintaining that code, maybe I'd dare to try fixing it, but would otherwise leave that to someone more knowledgable.

    @brada4:
    I'd be very cautious in trying to follow that FreeBSD's manpage.
    From what I've tried so far, on 64-bit Linux, Darwin, and Windows (with Intel's C compiler), 80-bit extended precision type is supported, in C as long double, in GNU Fortran as real(10), and stored as 16 bytes, of which the upper 6 bytes are unused.
    Therefore, what that manpage says about storing extended floats into 12 bytes is puzzling me.
    I don't have any FreeBSD installation around, but do have an OpenBSD 5.8 64-bit, and it also uses 16 bytes per a long double.

  12. brada4 commented on Feb 1, 2016

    @brada4
    Contributor

    I would say that this xdot kernel is still being compiled by accident, just disable it. There is no chance it will ever work on all systems it kind of compiles for.
    PS Darwin math library is from FreeBSD...

  13. added a commit that references this issue on Feb 2, 2016
  14. xianyi commented on Feb 2, 2016

    @xianyi
    Collaborator

    Just swap the result at the end of kernel.

  15. added a commit that references this issue on Feb 2, 2016
  16. venovako commented on Feb 2, 2016

    @venovako
    Author

    @xianyi:

    Thank you!

    I see the correct results now, and will close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions