1.23
2.0
main
test-branch
|
Last change
on this file since a8ca3d3 was f50dca2, checked in by Manchun Zheng <zmanchun@…>, 12 years ago |
|
added an example for cuda (from the paper "Formal Semantics of Heterogeneous CUDA-C: A Modular Approach with Applications").
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@637 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
613 bytes
|
| Line | |
|---|
| 1 | void __sync_init(int* in_barrier, int size) {
|
|---|
| 2 | barrier_size = size;
|
|---|
| 3 | for (int i=0; i<size; i++) in_barrier[i] = 0;
|
|---|
| 4 | }
|
|---|
| 5 |
|
|---|
| 6 | // model the synchronization of threads in the same block
|
|---|
| 7 | void __syncthreads(int* in_barrier, int tid) {
|
|---|
| 8 | $atomic {
|
|---|
| 9 | in_barrier[tid] = 1; // I am in the barrier
|
|---|
| 10 | num_in_barrier++; // increment number in barrier
|
|---|
| 11 | if (num_in_barrier == barrier_size) { // I am last to enter
|
|---|
| 12 | for (int i=0; i<barrier_size; i++)
|
|---|
| 13 | in_barrier[i] = 0; // release all
|
|---|
| 14 | num_in_barrier = 0; // now none are in barrier
|
|---|
| 15 | }
|
|---|
| 16 | }
|
|---|
| 17 | $when (in_barrier[tid] == 0); // wait till I am released
|
|---|
| 18 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.