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

[async] [cuda] AsyncEngine now supports CUDA #1687

Merged
merged 12 commits into from
Aug 12, 2020

Conversation

yuanming-hu
Copy link
Member

@@ -673,8 +673,6 @@ def to_numpy(self, keep_dims=False, as_vector=None):
ret = np.zeros(self.shape + shape_ext, dtype=to_numpy_type(self.dtype))
from .meta import matrix_to_ext_arr
matrix_to_ext_arr(self, ret, as_vector)
import taichi as ti
ti.sync()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since we already synchronize in Kernel.__call__

Comment on lines -99 to +100
static std::unordered_map<std::thread::id, CUDAContext *> instances;
static std::mutex mut;
{
// critical section
auto _ = std::lock_guard<std::mutex>(mut);

auto tid = std::this_thread::get_id();
if (instances.find(tid) == instances.end()) {
instances[tid] = new CUDAContext();
// We expect CUDAContext to live until the process ends, thus the raw
// pointers and `new`s.
}
return *instances[tid];
}
static auto context = new CUDAContext();
return *context;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't exactly remember why I had to create a standalone CUDAContext for each thread.

Creating a single context seems to work well.

@@ -1,5 +1,7 @@
#pragma once
Copy link
Member Author

@yuanming-hu yuanming-hu Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now we have one CUDAContext shared by all threads, I add mutex to serialize the driver API calls.

@yuanming-hu yuanming-hu requested a review from k-ye August 12, 2020 04:43
@codecov
Copy link

codecov bot commented Aug 12, 2020

Codecov Report

Merging #1687 into master will increase coverage by 0.03%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1687      +/-   ##
==========================================
+ Coverage   43.78%   43.82%   +0.03%     
==========================================
  Files          42       42              
  Lines        5940     5940              
  Branches     1023     1024       +1     
==========================================
+ Hits         2601     2603       +2     
+ Misses       3189     3187       -2     
  Partials      150      150              
Impacted Files Coverage Δ
python/taichi/lang/matrix.py 67.42% <ø> (-0.10%) ⬇️
python/taichi/lang/kernel.py 69.51% <75.00%> (+0.63%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55d6794...5ae867a. Read the comment docs.

Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@yuanming-hu yuanming-hu merged commit 53db565 into taichi-dev:master Aug 12, 2020
@yuanming-hu yuanming-hu mentioned this pull request Aug 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants