From 9914e0918b353e6da47e66d1d0931f5f2645bb23 Mon Sep 17 00:00:00 2001 From: Dun Liang Date: Fri, 1 Oct 2021 19:14:25 +0800 Subject: [PATCH] polish msvc crt shared link with -MD --- python/jittor/compiler.py | 3 +- python/jittor/src/misc/intrin.h | 30 ++++++++++++++++++++ python/jittor/src/misc/nano_vector.h | 17 +---------- python/jittor/src/profiler/simple_profiler.h | 19 ++----------- python/jittor/src/utils/log.cc | 3 +- python/jittor_utils/install_msvc.py | 2 +- 6 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 python/jittor/src/misc/intrin.h diff --git a/python/jittor/compiler.py b/python/jittor/compiler.py index e76369b7..ba229216 100644 --- a/python/jittor/compiler.py +++ b/python/jittor/compiler.py @@ -1055,7 +1055,7 @@ if os.name == 'nt': cc_flags = cc_flags.replace("-lstdc++", "") cc_flags = cc_flags.replace("-ldl", "") cc_flags += f" -L\"{py3_link_path}\" -lpython3{sys.version_info.minor} " - cc_flags += " -EHa " + cc_flags += " -EHa -MD " import jittor_utils if jittor_utils.msvc_path: mp = jittor_utils.msvc_path @@ -1142,6 +1142,7 @@ if has_cuda: if os.name == 'nt': nvcc_flags = nvcc_flags.replace("-fp:", "-Xcompiler -fp:") nvcc_flags = nvcc_flags.replace("-EHa", "-Xcompiler -EHa") + nvcc_flags = nvcc_flags.replace("-M", "-Xcompiler -M") nvcc_flags = nvcc_flags.replace("-nologo", "") nvcc_flags = nvcc_flags.replace("-std:", "-std=") nvcc_flags = nvcc_flags.replace("-Fo:", "-o") diff --git a/python/jittor/src/misc/intrin.h b/python/jittor/src/misc/intrin.h new file mode 100644 index 00000000..2af0671e --- /dev/null +++ b/python/jittor/src/misc/intrin.h @@ -0,0 +1,30 @@ +// *************************************************************** +// Copyright (c) 2021 Jittor. All Rights Reserved. +// Maintainers: Dun Liang . +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. +// *************************************************************** +#pragma once +#include "common.h" + +namespace jittor { + +static inline int lzcnt(int64 v) { + #ifdef __clang__ + #if __has_feature(__builtin_ia32_lzcnt_u64) + return __builtin_ia32_lzcnt_u64(v); + #else + return v ? __builtin_clzll(v) : 64; + #endif + #else + #ifdef _MSC_VER + unsigned long index; + _BitScanReverse64(&index, v); + return v ? 63-index : 64; + #else + return __builtin_clzll(v); + #endif + #endif +} + +} \ No newline at end of file diff --git a/python/jittor/src/misc/nano_vector.h b/python/jittor/src/misc/nano_vector.h index 2c348071..983d834a 100644 --- a/python/jittor/src/misc/nano_vector.h +++ b/python/jittor/src/misc/nano_vector.h @@ -6,25 +6,10 @@ // *************************************************************** #pragma once #include "common.h" +#include "misc/intrin.h" namespace jittor { -static inline int lzcnt(int64 v) { - #ifdef __clang__ - #if __has_feature(__builtin_ia32_lzcnt_u64) - return __builtin_ia32_lzcnt_u64(v); - #else - return v ? __builtin_clzll(v) : 64; - #endif - #else - #ifdef _MSC_VER - return __lzcnt64(v); - #else - return __builtin_clzll(v); - #endif - #endif -} - struct Slice { int64 start, stop, step, mask; inline void fill(int64 size) { diff --git a/python/jittor/src/profiler/simple_profiler.h b/python/jittor/src/profiler/simple_profiler.h index c70d6cd3..312a23f9 100644 --- a/python/jittor/src/profiler/simple_profiler.h +++ b/python/jittor/src/profiler/simple_profiler.h @@ -8,25 +8,10 @@ #include #include #include "common.h" +#include "misc/intrin.h" namespace jittor { -static inline int _lzcnt(int64 v) { - #ifdef __clang__ - #if __has_feature(__builtin_ia32_lzcnt_u64) - return __builtin_ia32_lzcnt_u64(v); - #else - return v ? __builtin_clzll(v) : 64; - #endif - #else - #ifdef _MSC_VER - return __lzcnt64(v); - #else - return __builtin_clzll(v); - #endif - #endif -} - struct SimpleProfiler { string name; int64 cnt; @@ -63,7 +48,7 @@ struct SimpleProfiler { inline SimpleProfiler(string&& name): name(move(name)), cnt(0), total_ns(0), sum(0) {} inline ~SimpleProfiler() { report(); } inline void add(int64 time, int64 s) { - auto nbit = 64 - _lzcnt(time); + auto nbit = 64 - lzcnt(time); auto i = (nbit-1) / 5; if (i>6) i=6; cnt ++; diff --git a/python/jittor/src/utils/log.cc b/python/jittor/src/utils/log.cc index e7aa4cba..a2e05729 100644 --- a/python/jittor/src/utils/log.cc +++ b/python/jittor/src/utils/log.cc @@ -494,7 +494,8 @@ int system_popen(const char *cmd, const char* cwd) { bSuccess = ReadFile(g_hChildStd_OUT_Rd, chBuf, BUFSIZ, &dwRead, NULL); if (!bSuccess || dwRead == 0) break; - output += chBuf; + output += string(chBuf, dwRead); + if (log_v) bSuccess = WriteFile(hParentStdOut, chBuf, dwRead, &dwWritten, NULL); diff --git a/python/jittor_utils/install_msvc.py b/python/jittor_utils/install_msvc.py index 018a4bf7..8203ca74 100644 --- a/python/jittor_utils/install_msvc.py +++ b/python/jittor_utils/install_msvc.py @@ -8,7 +8,7 @@ def install(path): LOG.i("Installing MSVC...") filename = "msvc.zip" url = "https://cg.cs.tsinghua.edu.cn/jittor/assets/" + filename - md5sum = "929c4b86ea68160121f73c3edf6b5463" + md5sum = "55f0c175fdf1419b124e0fc498b659d2" download_url_to_local(url, filename, path, md5sum) fullname = os.path.join(path, filename) import zipfile