Skip to content

Commit 08d6f8e

Browse files
committed
parallel compiler fix
1 parent 4d989e9 commit 08d6f8e

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

python/jittor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This file is subject to the terms and conditions defined in
88
# file 'LICENSE.txt', which is part of this source code package.
99
# ***************************************************************
10-
__version__ = '1.2.1.1'
10+
__version__ = '1.2.1.2'
1111
from . import lock
1212
with lock.lock_scope():
1313
ori_int = int

src/jit_key.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ inline JK& operator<<(JK& jk, const string& s) {
9292
auto a = (__jk_int256*)(jk.buffer+jk.size);
9393
auto b = (__jk_int256*)(&s[0]);
9494
auto len = s.size();
95-
for (uint64 i=0; i*32<len; i++)
96-
a[i] = b[i];
95+
uint64 i=0;
96+
for (; i+32<=len; i+=32)
97+
a[i/32] = b[i/32];
98+
99+
for (; i<len; i++)
100+
jk.buffer[jk.size+i] = s[i];
97101
jk.size += len;
98102
return jk;
99103
}

src/parallel_compiler.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct SimpleThread {
3737
std::thread thread;
3838
void run() {
3939
thread_name = "C"+S(id);
40-
try{
40+
try {
4141
std::unique_lock<std::mutex> lck(mtx);
4242
if (func)
4343
func(id);
@@ -75,6 +75,24 @@ struct SimpleThreads {
7575
for (int i=0; i<n; i++)
7676
threads.emplace_back(i);
7777
}
78+
void wait_all() {
79+
for (auto& t : threads) {
80+
auto start = clock();
81+
int ok = 0;
82+
while (clock()<start+5000) {
83+
if (t.mtx.try_lock()) {
84+
t.mtx.unlock();
85+
ok = 1;
86+
break;
87+
}
88+
using namespace std::chrono_literals;
89+
std::this_thread::sleep_for(1ms);
90+
}
91+
if (!ok) {
92+
LOGw << "Compile thread timeout, ignored.";
93+
}
94+
}
95+
}
7896
void launch_all(int active_thread, SimpleThread::Func func) {
7997
if (active_thread == 1) {
8098
func(0);
@@ -289,10 +307,12 @@ void parallel_compile_all_ops(vector<int>& queue, vector<int>& range, FusedOp& f
289307

290308
if (segfault_happen) {
291309
LOGe << "Segfault happen, main thread exit";
310+
threads.wait_all();
292311
exit(1);
293312
}
294313

295314
if (has_error) {
315+
threads.wait_all();
296316
LOGf << "Error happend during compilation, see error above.";
297317
}
298318

0 commit comments

Comments
 (0)