Skip to content

Commit 1296c89

Browse files
authored
Merge pull request #1256 from isuruf/develop
Support compiling with clang on windows
2 parents 0bfe5c6 + 7abbe40 commit 1296c89

File tree

12 files changed

+140
-67
lines changed

12 files changed

+140
-67
lines changed

appveyor.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,36 @@ clone_folder: c:\projects\OpenBLAS
1212
init:
1313
- git config --global core.autocrlf input
1414

15-
build:
16-
project: OpenBLAS.sln
17-
1815
clone_depth: 5
1916

20-
#branches to build
21-
branches:
22-
only:
23-
- master
24-
- develop
25-
- cmake
26-
2717
skip_tags: true
2818

2919
matrix:
30-
fast_finish: true
20+
fast_finish: false
3121

3222
skip_commits:
3323
# Add [av skip] to commit messages
3424
message: /\[av skip\]/
3525

26+
environment:
27+
matrix:
28+
- COMPILER: clang-cl
29+
- COMPILER: cl
30+
31+
install:
32+
- if [%COMPILER%]==[clang-cl] call C:\Miniconda36-x64\Scripts\activate.bat
33+
- if [%COMPILER%]==[clang-cl] conda config --add channels conda-forge --force
34+
- if [%COMPILER%]==[clang-cl] conda install --yes clangdev ninja cmake
35+
- if [%COMPILER%]==[clang-cl] call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
36+
3637
before_build:
3738
- echo Running cmake...
3839
- cd c:\projects\OpenBLAS
39-
- cmake -G "Visual Studio 12 Win64" .
40+
- if [%COMPILER%]==[cl] cmake -G "Visual Studio 12 Win64" .
41+
- if [%COMPILER%]==[clang-cl] cmake -G "Ninja" -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_C_COMPILER=clang-cl .
42+
43+
build_script:
44+
- cmake --build .
4045

4146
test_script:
4247
- echo Running Test

cmake/c_check.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
set(FU "")
2929
if(APPLE)
3030
set(FU "_")
31+
elseif(MSVC AND ${CMAKE_C_COMPILER_ID} MATCHES "Clang")
32+
set(FU "")
3133
elseif(MSVC)
3234
set(FU "_")
3335
elseif(UNIX)
@@ -59,7 +61,8 @@ endif ()
5961
# CMAKE_HOST_SYSTEM_PROCESSOR - The name of the CPU CMake is running on.
6062
#
6163
# TODO: CMAKE_SYSTEM_PROCESSOR doesn't seem to be correct - instead get it from the compiler a la c_check
62-
set(ARCH ${CMAKE_SYSTEM_PROCESSOR})
64+
set(ARCH ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "Target Architecture")
65+
6366
if (${ARCH} STREQUAL "AMD64")
6467
set(ARCH "x86_64")
6568
endif ()

cmake/export.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ else()
5151
endif()
5252

5353
add_custom_command(
54-
TARGET ${OpenBLAS_LIBNAME} PRE_LINK
54+
OUTPUT ${PROJECT_BINARY_DIR}/openblas.def
55+
#TARGET ${OpenBLAS_LIBNAME} PRE_LINK
5556
COMMAND perl
5657
ARGS "${PROJECT_SOURCE_DIR}/exports/gensymbol" "win2k" "${ARCH_IN}" "dummy" "${EXPRECISION_IN}" "${NO_CBLAS_IN}" "${NO_LAPACK_IN}" "${NO_LAPACKE_IN}" "${NEED2UNDERSCORES_IN}" "${ONLY_CBLAS_IN}" "${SYMBOLPREFIX}" "${SYMBOLSUFFIX}" > "${PROJECT_BINARY_DIR}/openblas.def"
5758
COMMENT "Create openblas.def file"

cmake/prebuild.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,14 @@ set(GETARCH_SRC
6464
${CPUIDEMO}
6565
)
6666

67-
if (NOT MSVC)
67+
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
68+
#Use generic for MSVC now
69+
message("MSVC")
70+
set(GETARCH_FLAGS ${GETARCH_FLAGS} -DFORCE_GENERIC)
71+
else()
6872
list(APPEND GETARCH_SRC ${PROJECT_SOURCE_DIR}/cpuid.S)
6973
endif ()
7074

71-
if (MSVC)
72-
#Use generic for MSVC now
73-
set(GETARCH_FLAGS ${GETARCH_FLAGS} -DFORCE_GENERIC)
74-
endif()
75-
7675
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
7776
# disable WindowsStore strict CRT checks
7877
set(GETARCH_FLAGS ${GETARCH_FLAGS} -D_CRT_SECURE_NO_WARNINGS)

common.h

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,33 @@ static void __inline blas_lock(volatile BLASULONG *address){
495495
#define MMAP_POLICY (MAP_PRIVATE | MAP_ANONYMOUS)
496496
#endif
497497

498+
#ifndef ASSEMBLER
499+
/* C99 supports complex floating numbers natively, which GCC also offers as an
500+
extension since version 3.0. If neither are available, use a compatible
501+
structure as fallback (see Clause 6.2.5.13 of the C99 standard). */
502+
#if ((defined(__STDC_IEC_559_COMPLEX__) || __STDC_VERSION__ >= 199901L || \
503+
(__GNUC__ >= 3 && !defined(__cplusplus))) && !(defined(FORCE_OPENBLAS_COMPLEX_STRUCT))) && !defined(_MSC_VER)
504+
#define OPENBLAS_COMPLEX_C99
505+
#ifndef __cplusplus
506+
#include <complex.h>
507+
#endif
508+
typedef float _Complex openblas_complex_float;
509+
typedef double _Complex openblas_complex_double;
510+
typedef xdouble _Complex openblas_complex_xdouble;
511+
#define openblas_make_complex_float(real, imag) ((real) + ((imag) * _Complex_I))
512+
#define openblas_make_complex_double(real, imag) ((real) + ((imag) * _Complex_I))
513+
#define openblas_make_complex_xdouble(real, imag) ((real) + ((imag) * _Complex_I))
514+
#else
515+
#define OPENBLAS_COMPLEX_STRUCT
516+
typedef struct { float real, imag; } openblas_complex_float;
517+
typedef struct { double real, imag; } openblas_complex_double;
518+
typedef struct { xdouble real, imag; } openblas_complex_xdouble;
519+
#define openblas_make_complex_float(real, imag) {(real), (imag)}
520+
#define openblas_make_complex_double(real, imag) {(real), (imag)}
521+
#define openblas_make_complex_xdouble(real, imag) {(real), (imag)}
522+
#endif
523+
#endif
524+
498525
#include "param.h"
499526
#include "common_param.h"
500527

@@ -524,31 +551,6 @@ static void __inline blas_lock(volatile BLASULONG *address){
524551
#include <stdio.h>
525552
#endif // NOINCLUDE
526553

527-
/* C99 supports complex floating numbers natively, which GCC also offers as an
528-
extension since version 3.0. If neither are available, use a compatible
529-
structure as fallback (see Clause 6.2.5.13 of the C99 standard). */
530-
#if ((defined(__STDC_IEC_559_COMPLEX__) || __STDC_VERSION__ >= 199901L || \
531-
(__GNUC__ >= 3 && !defined(__cplusplus))) && !(defined(FORCE_OPENBLAS_COMPLEX_STRUCT)))
532-
#define OPENBLAS_COMPLEX_C99
533-
#ifndef __cplusplus
534-
#include <complex.h>
535-
#endif
536-
typedef float _Complex openblas_complex_float;
537-
typedef double _Complex openblas_complex_double;
538-
typedef xdouble _Complex openblas_complex_xdouble;
539-
#define openblas_make_complex_float(real, imag) ((real) + ((imag) * _Complex_I))
540-
#define openblas_make_complex_double(real, imag) ((real) + ((imag) * _Complex_I))
541-
#define openblas_make_complex_xdouble(real, imag) ((real) + ((imag) * _Complex_I))
542-
#else
543-
#define OPENBLAS_COMPLEX_STRUCT
544-
typedef struct { float real, imag; } openblas_complex_float;
545-
typedef struct { double real, imag; } openblas_complex_double;
546-
typedef struct { xdouble real, imag; } openblas_complex_xdouble;
547-
#define openblas_make_complex_float(real, imag) {(real), (imag)}
548-
#define openblas_make_complex_double(real, imag) {(real), (imag)}
549-
#define openblas_make_complex_xdouble(real, imag) {(real), (imag)}
550-
#endif
551-
552554
#ifdef XDOUBLE
553555
#define OPENBLAS_COMPLEX_FLOAT openblas_complex_xdouble
554556
#define OPENBLAS_MAKE_COMPLEX_FLOAT(r,i) openblas_make_complex_xdouble(r,i)

common_param.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ BLASLONG (*icamin_k)(BLASLONG, float *, BLASLONG);
333333
float (*cnrm2_k) (BLASLONG, float *, BLASLONG);
334334
float (*casum_k) (BLASLONG, float *, BLASLONG);
335335
int (*ccopy_k) (BLASLONG, float *, BLASLONG, float *, BLASLONG);
336-
float _Complex (*cdotu_k) (BLASLONG, float *, BLASLONG, float *, BLASLONG);
337-
float _Complex (*cdotc_k) (BLASLONG, float *, BLASLONG, float *, BLASLONG);
336+
openblas_complex_float (*cdotu_k) (BLASLONG, float *, BLASLONG, float *, BLASLONG);
337+
openblas_complex_float (*cdotc_k) (BLASLONG, float *, BLASLONG, float *, BLASLONG);
338338
int (*csrot_k) (BLASLONG, float *, BLASLONG, float *, BLASLONG, float, float);
339339

340340
int (*caxpy_k) (BLASLONG, BLASLONG, BLASLONG, float, float, float *, BLASLONG, float *, BLASLONG, float *, BLASLONG);
@@ -496,8 +496,8 @@ BLASLONG (*izamin_k)(BLASLONG, double *, BLASLONG);
496496
double (*znrm2_k) (BLASLONG, double *, BLASLONG);
497497
double (*zasum_k) (BLASLONG, double *, BLASLONG);
498498
int (*zcopy_k) (BLASLONG, double *, BLASLONG, double *, BLASLONG);
499-
double _Complex (*zdotu_k) (BLASLONG, double *, BLASLONG, double *, BLASLONG);
500-
double _Complex (*zdotc_k) (BLASLONG, double *, BLASLONG, double *, BLASLONG);
499+
openblas_complex_double (*zdotu_k) (BLASLONG, double *, BLASLONG, double *, BLASLONG);
500+
openblas_complex_double (*zdotc_k) (BLASLONG, double *, BLASLONG, double *, BLASLONG);
501501
int (*zdrot_k) (BLASLONG, double *, BLASLONG, double *, BLASLONG, double, double);
502502

503503
int (*zaxpy_k) (BLASLONG, BLASLONG, BLASLONG, double, double, double *, BLASLONG, double *, BLASLONG, double *, BLASLONG);
@@ -661,8 +661,8 @@ BLASLONG (*ixamin_k)(BLASLONG, xdouble *, BLASLONG);
661661
xdouble (*xnrm2_k) (BLASLONG, xdouble *, BLASLONG);
662662
xdouble (*xasum_k) (BLASLONG, xdouble *, BLASLONG);
663663
int (*xcopy_k) (BLASLONG, xdouble *, BLASLONG, xdouble *, BLASLONG);
664-
xdouble _Complex (*xdotu_k) (BLASLONG, xdouble *, BLASLONG, xdouble *, BLASLONG);
665-
xdouble _Complex (*xdotc_k) (BLASLONG, xdouble *, BLASLONG, xdouble *, BLASLONG);
664+
openblas_complex_xdouble (*xdotu_k) (BLASLONG, xdouble *, BLASLONG, xdouble *, BLASLONG);
665+
openblas_complex_xdouble (*xdotc_k) (BLASLONG, xdouble *, BLASLONG, xdouble *, BLASLONG);
666666
int (*xqrot_k) (BLASLONG, xdouble *, BLASLONG, xdouble *, BLASLONG, xdouble, xdouble);
667667

668668
int (*xaxpy_k) (BLASLONG, BLASLONG, BLASLONG, xdouble, xdouble, xdouble *, BLASLONG, xdouble *, BLASLONG, xdouble *, BLASLONG);

kernel/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ParseMakefileVars("${KERNELDIR}/KERNEL")
2323
ParseMakefileVars("${KERNELDIR}/KERNEL.${TARGET_CORE}")
2424

2525
if (${ARCH} STREQUAL "x86")
26-
if (NOT MSVC)
26+
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
2727
GenerateNamedObjects("${KERNELDIR}/cpuid.S" "" "" false "" "" true)
2828
else()
2929
GenerateNamedObjects("${KERNELDIR}/cpuid_win.c" "" "" false "" "" true)

kernel/x86_64/cdot.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,15 @@ static void cdot_kernel_16(BLASLONG n, FLOAT *x, FLOAT *y, FLOAT *d)
9191

9292
#endif
9393

94-
FLOAT _Complex CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
94+
OPENBLAS_COMPLEX_FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
9595
{
9696
BLASLONG i;
9797
BLASLONG ix,iy;
98-
FLOAT _Complex result;
9998
FLOAT dot[8] = { 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0 } ;
10099

101100
if ( n <= 0 )
102101
{
103-
result = OPENBLAS_MAKE_COMPLEX_FLOAT (0.0, 0.0) ;
102+
OPENBLAS_COMPLEX_FLOAT result = OPENBLAS_MAKE_COMPLEX_FLOAT (0.0, 0.0) ;
104103
return(result);
105104

106105
}
@@ -160,11 +159,11 @@ FLOAT _Complex CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG in
160159
}
161160

162161
#if !defined(CONJ)
163-
result = OPENBLAS_MAKE_COMPLEX_FLOAT (dot[0]-dot[1], dot[4]+dot[5]) ;
162+
OPENBLAS_COMPLEX_FLOAT result = OPENBLAS_MAKE_COMPLEX_FLOAT (dot[0]-dot[1], dot[4]+dot[5]) ;
164163
// CREAL(result) = dot[0] - dot[1];
165164
// CIMAG(result) = dot[4] + dot[5];
166165
#else
167-
result = OPENBLAS_MAKE_COMPLEX_FLOAT (dot[0]+dot[1], dot[4]-dot[5]) ;
166+
OPENBLAS_COMPLEX_FLOAT result = OPENBLAS_MAKE_COMPLEX_FLOAT (dot[0]+dot[1], dot[4]-dot[5]) ;
168167
// CREAL(result) = dot[0] + dot[1];
169168
// CIMAG(result) = dot[4] - dot[5];
170169

kernel/x86_64/zdot.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,17 @@ static void zdot_kernel_8(BLASLONG n, FLOAT *x, FLOAT *y, FLOAT *d)
8686

8787
#endif
8888

89-
FLOAT _Complex CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
89+
OPENBLAS_COMPLEX_FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
9090
{
9191
BLASLONG i;
9292
BLASLONG ix,iy;
93-
FLOAT _Complex result;
9493
FLOAT dot[4] = { 0.0, 0.0, 0.0 , 0.0 } ;
9594

9695
if ( n <= 0 )
9796
{
9897
// CREAL(result) = 0.0 ;
9998
// CIMAG(result) = 0.0 ;
100-
result=OPENBLAS_MAKE_COMPLEX_FLOAT(0.0,0.0);
99+
OPENBLAS_COMPLEX_FLOAT result=OPENBLAS_MAKE_COMPLEX_FLOAT(0.0,0.0);
101100
return(result);
102101

103102
}
@@ -151,11 +150,11 @@ FLOAT _Complex CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG in
151150
}
152151

153152
#if !defined(CONJ)
154-
result=OPENBLAS_MAKE_COMPLEX_FLOAT(dot[0]-dot[1],dot[2]+dot[3]);
153+
OPENBLAS_COMPLEX_FLOAT result=OPENBLAS_MAKE_COMPLEX_FLOAT(dot[0]-dot[1],dot[2]+dot[3]);
155154
// CREAL(result) = dot[0] - dot[1];
156155
// CIMAG(result) = dot[2] + dot[3];
157156
#else
158-
result=OPENBLAS_MAKE_COMPLEX_FLOAT(dot[0]+dot[1],dot[2]-dot[3]);
157+
OPENBLAS_COMPLEX_FLOAT result=OPENBLAS_MAKE_COMPLEX_FLOAT(dot[0]+dot[1],dot[2]-dot[3]);
159158
// CREAL(result) = dot[0] + dot[1];
160159
// CIMAG(result) = dot[2] - dot[3];
161160

openblas_config_template.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ typedef int blasint;
5959
extension since version 3.0. If neither are available, use a compatible
6060
structure as fallback (see Clause 6.2.5.13 of the C99 standard). */
6161
#if ((defined(__STDC_IEC_559_COMPLEX__) || __STDC_VERSION__ >= 199901L || \
62-
(__GNUC__ >= 3 && !defined(__cplusplus))) && !(defined(FORCE_OPENBLAS_COMPLEX_STRUCT)))
62+
(__GNUC__ >= 3 && !defined(__cplusplus))) && !(defined(FORCE_OPENBLAS_COMPLEX_STRUCT))) && !defined(_MSC_VER)
6363
#define OPENBLAS_COMPLEX_C99
6464
#ifndef __cplusplus
6565
#include <complex.h>

utest/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
include_directories(${PROJECT_SOURCE_DIR})
22
include_directories(${PROJECT_BINARY_DIR})
33

4-
set(OpenBLAS_utest_src
5-
utest_main.c
6-
test_amax.c
4+
if (MSVC AND "${CMAKE_C_COMPILER_ID}" MATCHES Clang)
5+
set(OpenBLAS_utest_src utest_main2.c)
6+
else ()
7+
set(OpenBLAS_utest_src
8+
utest_main.c
9+
test_amax.c
710
)
11+
endif ()
812

913
if (NOT NO_LAPACK)
1014
set(OpenBLAS_utest_src
@@ -36,7 +40,7 @@ endforeach()
3640
if (MSVC)
3741
add_custom_command(TARGET ${OpenBLAS_utest_bin}
3842
POST_BUILD
39-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lib/$<CONFIG>/${OpenBLAS_LIBNAME}.dll ${CMAKE_CURRENT_BINARY_DIR}/.
43+
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lib/${CMAKE_CFG_INTDIR}/${OpenBLAS_LIBNAME}.dll ${CMAKE_CURRENT_BINARY_DIR}/.
4044
)
4145
endif()
4246

utest/utest_main2.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2016, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
3. Neither the name of the OpenBLAS project nor the names of
17+
its contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
**********************************************************************************/
33+
34+
#include <stdio.h>
35+
36+
#define CTEST_MAIN
37+
#define CTEST_SEGFAULT
38+
#define CTEST_ADD_TESTS_MANUALLY
39+
40+
#include "openblas_utest.h"
41+
42+
CTEST(amax, samax){
43+
blasint N=3, inc=1;
44+
float te_max=0.0, tr_max=0.0;
45+
float x[]={-1.1, 2.2, -3.3};
46+
te_max=BLASFUNC(samax)(&N, x, &inc);
47+
tr_max=3.3;
48+
49+
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
50+
}
51+
52+
int main(int argc, const char ** argv){
53+
54+
CTEST_ADD(amax, samax);
55+
int num_fail=0;
56+
57+
num_fail=ctest_main(argc, argv);
58+
59+
return num_fail;
60+
}
61+

0 commit comments

Comments
 (0)