-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.w32
More file actions
239 lines (214 loc) · 12.6 KB
/
Copy pathconfig.w32
File metadata and controls
239 lines (214 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// vim:ft=javascript
//
// Windows PHP SDK build configuration for the ndarray (NumPower) extension.
// Mirrors config.m4 / configure.ac:
// - links against OpenBLAS (cblas_sdot) and LAPACKE (LAPACKE_sgesdd),
// - opts in to AVX2 on x64 via /arch:AVX2 (matches -mavx2 on POSIX),
// - opts in to CUDA / cuDNN via --with-cuda when the CUDA Toolkit is
// available (the .cu sources must be pre-compiled into ndarray_cuda.lib
// via build-cuda-windows.bat; nmake then links that .lib alongside
// cublas.lib / cudart.lib / cudnn.lib),
// - leaves MKL, libquadmath, and GD disabled (no MSVC-side support yet);
// float128 falls back to long double via the gate in src/ndarray_types.h.
//
// Lookup order for OpenBLAS / LAPACKE: --with-openblas-dir=<path> takes
// precedence; otherwise we fall back to the OPENBLAS_DIR environment
// variable, the PHP SDK deps tree (deps/include / deps/lib) and finally the
// standard CHECK_HEADER / CHECK_LIB search paths populated by phpsdk_deps.
//
// Lookup order for CUDA: --with-cuda-dir=<path> takes precedence over the
// CUDA_PATH environment variable (set by the standard NVIDIA installer).
// cuDNN is auto-detected inside the CUDA tree, or via --with-cudnn-dir=<path>
// when installed separately.
ARG_ENABLE("ndarray", "whether to enable ndarray (NumPower) support", "no");
ARG_WITH("openblas-dir", "OpenBLAS install prefix (contains include\\ and lib\\)", "no");
ARG_WITH("cuda", "whether to enable CUDA (GPU) support", "no");
ARG_WITH("cuda-dir", "CUDA Toolkit install prefix (contains bin\\, include\\, lib\\x64\\)", "no");
ARG_WITH("cudnn-dir", "cuDNN install prefix when not bundled inside the CUDA tree", "no");
if (PHP_NDARRAY != "no") {
var openblas_root = (PHP_OPENBLAS_DIR && PHP_OPENBLAS_DIR != "no")
? PHP_OPENBLAS_DIR
: (WshShell.Environment("PROCESS").Item("OPENBLAS_DIR") || "");
var extra_inc = "";
var extra_lib = "";
if (openblas_root && openblas_root.length > 0) {
extra_inc = openblas_root + "\\include;" +
openblas_root + "\\include\\openblas;";
extra_lib = openblas_root + "\\lib;";
ADD_FLAG("LDFLAGS_NDARRAY", "/libpath:\"" + openblas_root + "\\lib\"");
ADD_FLAG("LDFLAGS_NDARRAY", "/libpath:\"" + openblas_root + "\\bin\"");
}
// Header probes — OpenBLAS ships cblas.h either at the include root or
// under include\openblas\ depending on the distribution.
var have_cblas_h =
CHECK_HEADER_ADD_INCLUDE("cblas.h", "CFLAGS_NDARRAY", extra_inc + configure_module_dirname) ||
CHECK_HEADER_ADD_INCLUDE("openblas\\cblas.h", "CFLAGS_NDARRAY", extra_inc + configure_module_dirname);
var have_lapacke_h =
CHECK_HEADER_ADD_INCLUDE("lapacke.h", "CFLAGS_NDARRAY", extra_inc + configure_module_dirname) ||
CHECK_HEADER_ADD_INCLUDE("openblas\\lapacke.h", "CFLAGS_NDARRAY", extra_inc + configure_module_dirname);
if (!have_cblas_h) {
WARNING("ndarray not enabled; cblas.h not found. Pass --with-openblas-dir=<path> or set %OPENBLAS_DIR%.");
} else if (!have_lapacke_h) {
WARNING("ndarray not enabled; lapacke.h not found. Pass --with-openblas-dir=<path> or set %OPENBLAS_DIR%.");
} else {
// OpenBLAS prebuilt distributions name their import library either
// "libopenblas.lib" (OpenMathLib release archives) or "openblas.lib"
// (vcpkg). Try both.
var blas_lib = null;
if (CHECK_LIB("libopenblas.lib", "ndarray", extra_lib)) {
blas_lib = "libopenblas.lib";
} else if (CHECK_LIB("openblas.lib", "ndarray", extra_lib)) {
blas_lib = "openblas.lib";
}
if (blas_lib === null) {
WARNING("ndarray not enabled; OpenBLAS import library (libopenblas.lib / openblas.lib) not found.");
} else {
AC_DEFINE("HAVE_CBLAS", 1, "Have CBLAS support");
AC_DEFINE("HAVE_LAPACKE", 1, "Have LAPACKE support");
// OpenBLAS exports both cblas_* and LAPACKE_* symbols from the
// same DLL, so a single import library satisfies both.
// HAVE_QUADMATH is consumed via `#if HAVE_QUADMATH` so a 0
// value correctly disables the libquadmath code path. The
// CUDA / cuDNN / MKL / GD feature flags are consumed via
// `#ifdef HAVE_xxx` in many sites, so we must leave them
// *undefined* to keep those paths out of the build.
// AVX2: on x64 it is always available on any CPU released since
// 2013 and matches the POSIX configure (which sets -mavx2 -march=
// native unconditionally on x86 hosts). On ARM64 it is mandatory
// to leave HAVE_AVX2=0 — the kernels are gated by this macro.
if (X64) {
AC_DEFINE("HAVE_AVX2", 1, "Have AVX2/SSE support");
ADD_FLAG("CFLAGS_NDARRAY", "/arch:AVX2");
} else {
AC_DEFINE("HAVE_AVX2", 0, "Have AVX2/SSE support");
}
// _USE_MATH_DEFINES: M_PI etc. used by trig/log helpers on POSIX
// are not in the C standard; MSVC only exposes them when this
// macro is defined before <math.h> is included.
// NOMINMAX: keep <windows.h> (pulled in transitively by some PHP
// headers) from clobbering std::min/std::max — not C++ here but
// also keeps min()/max() macros from biting AVX2 kernels.
ADD_FLAG("CFLAGS_NDARRAY", "/D_USE_MATH_DEFINES /DNOMINMAX");
// ─────────────────────────────────────────────────────────────
// CUDA / cuDNN
//
// Opt-in via --with-cuda. The .cu sources (cuda_math.cu,
// cuda_dnn.cu) cannot be compiled by cl.exe — they must be
// pre-built into ndarray_cuda.lib by build-cuda-windows.bat
// before `nmake` runs. config.w32 here only handles:
// 1. locating the CUDA Toolkit + cuDNN libs,
// 2. defining HAVE_CUBLAS / HAVE_CUDNN so the .c sources
// compile the GPU dispatch branches,
// 3. wiring cublas.lib / cudart.lib / cudnn.lib /
// ndarray_cuda.lib into the link.
//
// The same /MD CRT mode (MSVC's multi-threaded DLL CRT) MUST be
// used by build-cuda-windows.bat when invoking nvcc, or the
// linker fails with LNK2038 "mismatch detected for _MSC_VER" /
// RuntimeLibrary mismatches.
// ─────────────────────────────────────────────────────────────
if (PHP_CUDA != "no") {
var cuda_root = (PHP_CUDA_DIR && PHP_CUDA_DIR != "no")
? PHP_CUDA_DIR
: (WshShell.Environment("PROCESS").Item("CUDA_PATH") || "");
if (!cuda_root || cuda_root.length == 0) {
WARNING("--with-cuda passed but no CUDA Toolkit found; pass --with-cuda-dir=<path> or set %CUDA_PATH%.");
} else {
var cuda_inc = cuda_root + "\\include";
var cuda_lib = cuda_root + "\\lib\\x64";
var have_cublas_h = CHECK_HEADER_ADD_INCLUDE(
"cublas_v2.h", "CFLAGS_NDARRAY",
cuda_inc + ";" + configure_module_dirname);
// cuda_math.cu calls into cusolverDn* (SVD, getrf, syevd,
// …) and src/initializers.c calls curand host functions
// (curandCreateGenerator, curandGenerateNormal, …), so
// cusolver.lib AND curand.lib must be in the link line.
// Windows' linker is strict on unresolved symbols (Linux
// gets away with deferred binding via dlopen(RTLD_LAZY),
// but that's a latent bug there too — runtime crash the
// first time anyone calls NumPower::svd / ::normal / etc.
// on a GPU array).
var have_cublas_lib = false;
if (have_cublas_h) {
ADD_FLAG("LDFLAGS_NDARRAY", "/libpath:\"" + cuda_lib + "\"");
have_cublas_lib =
CHECK_LIB("cublas.lib", "ndarray", cuda_lib) &&
CHECK_LIB("cudart.lib", "ndarray", cuda_lib) &&
CHECK_LIB("cusolver.lib", "ndarray", cuda_lib) &&
CHECK_LIB("curand.lib", "ndarray", cuda_lib);
}
if (!have_cublas_h || !have_cublas_lib) {
WARNING("CUDA enabled but cublas_v2.h / cublas.lib / cudart.lib / cusolver.lib / curand.lib not found under \"" + cuda_root + "\"; GPU support disabled.");
} else {
AC_DEFINE("HAVE_CUBLAS", 1, "Have cuBLAS / cudart / cusolver / curand support");
ADD_FLAG("LIBS_NDARRAY", "cublas.lib cudart.lib cusolver.lib curand.lib");
// cuDNN: optional. Prefer --with-cudnn-dir, then look
// inside the CUDA tree (newer Toolkits ship cuDNN
// headers alongside the rest under include\).
var cudnn_root = (PHP_CUDNN_DIR && PHP_CUDNN_DIR != "no")
? PHP_CUDNN_DIR
: cuda_root;
var cudnn_inc = cudnn_root + "\\include";
var cudnn_lib = cudnn_root + "\\lib\\x64";
var have_cudnn_h = CHECK_HEADER_ADD_INCLUDE(
"cudnn.h", "CFLAGS_NDARRAY",
cudnn_inc + ";" + configure_module_dirname);
if (have_cudnn_h) {
if (cudnn_root != cuda_root) {
ADD_FLAG("LDFLAGS_NDARRAY", "/libpath:\"" + cudnn_lib + "\"");
}
if (CHECK_LIB("cudnn.lib", "ndarray", cudnn_lib)) {
AC_DEFINE("HAVE_CUDNN", 1, "Have cuDNN support");
ADD_FLAG("LIBS_NDARRAY", "cudnn.lib");
} else {
STDOUT.WriteLine(" cudnn.h found but cudnn.lib not located; cuDNN disabled.");
}
} else {
STDOUT.WriteLine(" cudnn.h not found; cuDNN GPU paths disabled (cublas/cudart still active).");
}
// ndarray_cuda.lib bundles the pre-compiled
// cuda_math.obj + cuda_dnn.obj (produced by
// build-cuda-windows.bat at the repo root). The
// linker searches the build CWD by default, but we
// add a /LIBPATH for safety in case nmake is run
// from a subdir.
ADD_FLAG("LDFLAGS_NDARRAY", "/libpath:\"" + configure_module_dirname + "\"");
ADD_FLAG("LIBS_NDARRAY", "ndarray_cuda.lib");
STDOUT.WriteLine(" CUDA enabled — remember to run build-cuda-windows.bat BEFORE nmake.");
}
}
}
AC_DEFINE("HAVE_NDARRAY", 1, "Have ndarray support");
// Source list — identical to PHP_NEW_EXTENSION in config.m4.
EXTENSION("ndarray", "numpower.c", PHP_NDARRAY_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
ADD_SOURCES(configure_module_dirname + "/src",
"initializers.c " +
"ndarray.c " +
"debug.c " +
"buffer.c " +
"logic.c " +
"gpu_alloc.c " +
"manipulation.c " +
"dnn.c " +
"iterators.c " +
"indexing.c " +
"sanitizers.c " +
"types.c " +
"ndarray_types.c " +
"dd_math.c",
"ndarray");
ADD_SOURCES(configure_module_dirname + "/src/ndmath",
"double_math.c " +
"linalg.c " +
"arithmetics.c " +
"calculation.c " +
"statistics.c " +
"signal.c",
"ndarray");
ADD_SOURCES(configure_module_dirname + "/src/ndarray/frontend",
"ndarray_factory.c " +
"manipulations.c",
"ndarray");
}
}
}