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

How can I deal with data race when I am creating a taichi-based hash map? The code runs successfully on CPU single thread. #8557

Open
pyh3552 opened this issue Jul 9, 2024 · 0 comments
Labels
question Question on using Taichi

Comments

@pyh3552
Copy link

pyh3552 commented Jul 9, 2024

@ti.func
    def find(self, k: ti.template(), create: bool = False) -> ti.int32:
        h = self._hash(k) % self.capacity_
        return_value = 0
        while True:
            e = ti.atomic_add(self.table_[h], 0)
            if (e == -1):
                if (create):
                    tmp = ti.atomic_add(self.filled_[None], 1)
                    for i in range(self.feature_dim_):
                        ti.atomic_add(self.features_[tmp * self.feature_dim_ + i], k[i])
                    self.table_[h] = tmp
                    return_value = tmp
                    # print("created")
                    break
                else: 
                    # ti.atomic_add(return_value, e)
                    return_value = ti.atomic_add(e, 0)
                    # print("not exist")
                    break
            good = True
            for i in range(self.feature_dim_):
                if good and self.features_[e * self.feature_dim_ + i] != k[i]:  
                    good = False
            if good:
                return_value = ti.atomic_add(e, 0)
                # print("found")
                break
            h += 1
            if (h == self.capacity_):
                h = 0
        # print(f"===============return{self.filled_[None]}=============")
        # print(return_value)
        return return_value
@pyh3552 pyh3552 added the question Question on using Taichi label Jul 9, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in Taichi Lang Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question on using Taichi
Projects
Status: Untriaged
Development

No branches or pull requests

1 participant