forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CUDA] Enable shared memory for CUDA (taichi-dev#5429)
* Implement shared memory for CUDA Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5f2e607
commit 7e74c76
Showing
10 changed files
with
112 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
from taichi.lang import impl | ||
from taichi.lang.util import taichi_scope | ||
|
||
|
||
def sync(): | ||
return impl.call_internal("block_barrier", with_runtime_context=False) | ||
|
||
|
||
class SharedArray: | ||
_is_taichi_class = True | ||
|
||
def __init__(self, shape, dtype): | ||
self.shape = shape | ||
self.dtype = dtype | ||
self.shared_array_proxy = impl.expr_init_shared_array(shape, dtype) | ||
|
||
@taichi_scope | ||
def _subscript(self, *indices, get_ref=False): | ||
return impl.make_index_expr(self.shared_array_proxy, (indices, )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import taichi as ti | ||
from tests import test_utils | ||
|
||
|
||
@test_utils.test(arch=ti.cuda) | ||
def test_shared_array_save(): | ||
block_dim = 128 | ||
pad_num = 16 | ||
a = ti.field(dtype=ti.f32, shape=(block_dim * pad_num, )) | ||
|
||
@ti.kernel | ||
def func(): | ||
ti.loop_config(block_dim=block_dim) | ||
for i in range(block_dim * pad_num): | ||
g_tid = ti.global_thread_idx() | ||
tid = g_tid % block_dim | ||
pad = ti.simt.block.SharedArray((block_dim, ), ti.f32) | ||
pad[tid] = tid * 2.0 | ||
ti.simt.block.sync() | ||
a[i] = pad[tid] | ||
ti.simt.block.sync() | ||
|
||
func() | ||
for i in range(pad_num): | ||
assert a[i * block_dim + 7] == 14.0 | ||
assert a[i * block_dim + 29] == 58.0 | ||
assert a[i * block_dim + 127] == 254.0 |