Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-threaded unit testing by pytest #483

Merged
merged 29 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
52bb002
Merge pull request #2 from taichi-dev/master
archibate Feb 14, 2020
954a7fe
Merge pull request #3 from taichi-dev/master
archibate Feb 16, 2020
c49f6e6
implement x ** y gradients #468 #469
archibate Feb 16, 2020
04ed4f8
enable pytest-xdist multi-threaded testing (#481)
archibate Feb 16, 2020
9bc49dc
enable pytest-xdist multi-threaded testing (#481)
archibate Feb 16, 2020
54d94cf
Merge branch 'feature-test' of github.com:archibate/taichi into featu…
archibate Feb 16, 2020
c8ed32a
_merged_ #479 by hand
archibate Feb 16, 2020
3a85f95
Merge branch 'feature-test' of github.com:archibate/taichi into featu…
archibate Feb 16, 2020
8a53f2a
Merge branch 'master' into feature-test
archibate Feb 16, 2020
adf2f4f
auto-compelete file name for #479
archibate Feb 16, 2020
056e683
test_verbose also support #479
archibate Feb 16, 2020
d628cec
Merge pull request #4 from taichi-dev/master
archibate Feb 17, 2020
6352f9f
Skip non-essential builds on AppVeyor #485
archibate Feb 17, 2020
cfa027d
try fix appveyor.yml
archibate Feb 17, 2020
766e742
mistake in appveyor_filter.py
archibate Feb 17, 2020
9c0f805
really fix appveyor_filter.py
archibate Feb 17, 2020
19603c3
try use `appveyor exit` & add msg in filter
archibate Feb 17, 2020
2322bd7
fix typo in appveyor_filter.py
archibate Feb 17, 2020
e7b7626
cache build in appveyor
archibate Feb 17, 2020
b3af94f
add test_files argument to test_cpp; better no test_cpp in test if ar…
archibate Feb 17, 2020
09feef4
Merge branch 'issue-485' into feature-test
archibate Feb 17, 2020
e44fda3
fix typo in python/taichi/main.py
archibate Feb 17, 2020
3afbbf0
add typo in main.py porpusely to figure out why travis fail because -n 2
archibate Feb 17, 2020
667a3ab
try again
archibate Feb 17, 2020
dad20f8
auto-detect pytest xdist
archibate Feb 17, 2020
d56de74
test_files: None -> ()
archibate Feb 17, 2020
57155f6
Merge branch 'master' into feature-test
archibate Feb 17, 2020
44e32be
add pytest-xdist to ci_setup.py
yuanming-hu Feb 17, 2020
82c7f18
remove appveyor.yml modifications
yuanming-hu Feb 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions python/taichi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,27 @@ def test_python(test_files=None, verbose=False):
if test_files:
# run individual tests
for f in test_files:
# auto-compelete
if not f.startswith('test_'):
f = 'test_' + f
if not f.endswith('.py'):
f = f + '.py'
args.append(os.path.join(test_dir, f))
else:
# run all the tests
args = [test_dir]
if verbose:
args += ['-s']
if not test_files or len(test_files) > 4:
try:
from multiprocessing import cpu_count
cpu_count = cpu_count()
except:
cpu_count = 4
print(f'Starting {cpu_count} testing thread(s)...')
args += ['-n', str(cpu_count)]

print('XXX')
return int(pytest.main(args))


Expand Down Expand Up @@ -104,11 +118,11 @@ def main(debug=False):
elif mode == "test_cpp":
return test_cpp()
elif mode == "test":
if test_python() != 0:
if test_python(test_files=sys.argv[2:]) != 0 or len(sys.argv) > 2:
yuanming-hu marked this conversation as resolved.
Show resolved Hide resolved
return -1
return test_cpp()
elif mode == "test_verbose":
if test_python(verbose=True) != 0:
if test_python(test_files=sys.argv[2:], verbose=True) != 0:
return -1
return test_cpp()
elif mode == "build":
Expand Down
14 changes: 14 additions & 0 deletions taichi/transforms/make_adjoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ class MakeAdjoint : public IRVisitor {
return insert<UnaryOpStmt>(UnaryOpType::sin, load(op1));
}

Stmt *log(Stmt *op1) {
return insert<UnaryOpStmt>(UnaryOpType::log, load(op1));
}

Stmt *pow(Stmt *op1, Stmt *op2) {
return insert<BinaryOpStmt>(BinaryOpType::pow, load(op1), load(op2));
}

public:
Block *current_block;
int for_depth;
Expand Down Expand Up @@ -189,6 +197,7 @@ class MakeAdjoint : public IRVisitor {
accumulate(bin->lhs, adjoint(bin));
accumulate(bin->rhs, negate(adjoint(bin)));
} else if (bin->op_type == BinaryOpType::mul) {
// d (x * y) = y * dx + x * dy
accumulate(bin->lhs, mul(adjoint(bin), bin->rhs));
accumulate(bin->rhs, mul(adjoint(bin), bin->lhs));
} else if (bin->op_type == BinaryOpType::mod) {
Expand All @@ -201,6 +210,11 @@ class MakeAdjoint : public IRVisitor {
auto numerator = add(sqr(bin->lhs), sqr(bin->rhs));
accumulate(bin->lhs, div(mul(adjoint(bin), bin->rhs), numerator));
accumulate(bin->rhs, negate(div(mul(adjoint(bin), bin->lhs), numerator)));
} else if (bin->op_type == BinaryOpType::pow) {
// d (x ^ y) = y * x ^ (y-1) dx + log(x) * x ^ y dy
accumulate(bin->lhs, mul(adjoint(bin),
mul(pow(bin->lhs, sub(bin->rhs, constant(1))), bin->rhs)));
accumulate(bin->rhs, mul(adjoint(bin), mul(log(bin->lhs), pow(bin->lhs, bin->rhs))));
} else if (bin->op_type == BinaryOpType::min ||
bin->op_type == BinaryOpType::max) {
auto cmp = bin->op_type == BinaryOpType::min ? cmp_lt(bin->lhs, bin->rhs)
Expand Down