polish msvc crt shared link with -MD

This commit is contained in:
Dun Liang 2021-10-01 19:14:25 +08:00
parent 1ccf45a03d
commit 9914e0918b
6 changed files with 38 additions and 36 deletions

View File

@ -1055,7 +1055,7 @@ if os.name == 'nt':
cc_flags = cc_flags.replace("-lstdc++", "") cc_flags = cc_flags.replace("-lstdc++", "")
cc_flags = cc_flags.replace("-ldl", "") cc_flags = cc_flags.replace("-ldl", "")
cc_flags += f" -L\"{py3_link_path}\" -lpython3{sys.version_info.minor} " cc_flags += f" -L\"{py3_link_path}\" -lpython3{sys.version_info.minor} "
cc_flags += " -EHa " cc_flags += " -EHa -MD "
import jittor_utils import jittor_utils
if jittor_utils.msvc_path: if jittor_utils.msvc_path:
mp = jittor_utils.msvc_path mp = jittor_utils.msvc_path
@ -1142,6 +1142,7 @@ if has_cuda:
if os.name == 'nt': if os.name == 'nt':
nvcc_flags = nvcc_flags.replace("-fp:", "-Xcompiler -fp:") nvcc_flags = nvcc_flags.replace("-fp:", "-Xcompiler -fp:")
nvcc_flags = nvcc_flags.replace("-EHa", "-Xcompiler -EHa") 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("-nologo", "")
nvcc_flags = nvcc_flags.replace("-std:", "-std=") nvcc_flags = nvcc_flags.replace("-std:", "-std=")
nvcc_flags = nvcc_flags.replace("-Fo:", "-o") nvcc_flags = nvcc_flags.replace("-Fo:", "-o")

View File

@ -0,0 +1,30 @@
// ***************************************************************
// Copyright (c) 2021 Jittor. All Rights Reserved.
// Maintainers: Dun Liang <randonlang@gmail.com>.
// 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
}
}

View File

@ -6,25 +6,10 @@
// *************************************************************** // ***************************************************************
#pragma once #pragma once
#include "common.h" #include "common.h"
#include "misc/intrin.h"
namespace jittor { 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 { struct Slice {
int64 start, stop, step, mask; int64 start, stop, step, mask;
inline void fill(int64 size) { inline void fill(int64 size) {

View File

@ -8,25 +8,10 @@
#include <chrono> #include <chrono>
#include <iomanip> #include <iomanip>
#include "common.h" #include "common.h"
#include "misc/intrin.h"
namespace jittor { 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 { struct SimpleProfiler {
string name; string name;
int64 cnt; int64 cnt;
@ -63,7 +48,7 @@ struct SimpleProfiler {
inline SimpleProfiler(string&& name): name(move(name)), cnt(0), total_ns(0), sum(0) {} inline SimpleProfiler(string&& name): name(move(name)), cnt(0), total_ns(0), sum(0) {}
inline ~SimpleProfiler() { report(); } inline ~SimpleProfiler() { report(); }
inline void add(int64 time, int64 s) { inline void add(int64 time, int64 s) {
auto nbit = 64 - _lzcnt(time); auto nbit = 64 - lzcnt(time);
auto i = (nbit-1) / 5; auto i = (nbit-1) / 5;
if (i>6) i=6; if (i>6) i=6;
cnt ++; cnt ++;

View File

@ -494,7 +494,8 @@ int system_popen(const char *cmd, const char* cwd) {
bSuccess = ReadFile(g_hChildStd_OUT_Rd, chBuf, BUFSIZ, &dwRead, NULL); bSuccess = ReadFile(g_hChildStd_OUT_Rd, chBuf, BUFSIZ, &dwRead, NULL);
if (!bSuccess || dwRead == 0) if (!bSuccess || dwRead == 0)
break; break;
output += chBuf; output += string(chBuf, dwRead);
if (log_v) if (log_v)
bSuccess = WriteFile(hParentStdOut, chBuf, bSuccess = WriteFile(hParentStdOut, chBuf,
dwRead, &dwWritten, NULL); dwRead, &dwWritten, NULL);

View File

@ -8,7 +8,7 @@ def install(path):
LOG.i("Installing MSVC...") LOG.i("Installing MSVC...")
filename = "msvc.zip" filename = "msvc.zip"
url = "https://cg.cs.tsinghua.edu.cn/jittor/assets/" + filename url = "https://cg.cs.tsinghua.edu.cn/jittor/assets/" + filename
md5sum = "929c4b86ea68160121f73c3edf6b5463" md5sum = "55f0c175fdf1419b124e0fc498b659d2"
download_url_to_local(url, filename, path, md5sum) download_url_to_local(url, filename, path, md5sum)
fullname = os.path.join(path, filename) fullname = os.path.join(path, filename)
import zipfile import zipfile