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

to_numpy() broken on macos 12.6 and vulkan #6217

Closed
joshu-vp opened this issue Sep 30, 2022 · 4 comments
Closed

to_numpy() broken on macos 12.6 and vulkan #6217

joshu-vp opened this issue Sep 30, 2022 · 4 comments
Assignees

Comments

@joshu-vp
Copy link

joshu-vp commented Sep 30, 2022

to_numpy() broken after upgrade to macos 12.6, on M1 chip

prints x.to_numpy() as [0, 0, 0, ..., 0]

import taichi as ti
import numpy as np

ti.init(arch=ti.vulkan)
num_particles = 1000

x = ti.Vector.field(2, dtype=ti.f32, shape=num_particles)

@ti.kernel
def substep():
    for i in range(num_particles):
        x[i] += x[i]

def main():
    for i in range(num_particles):
        x[i] = ti.Vector(np.random.rand(2), dt=ti.f32)
    substep()
    print(x.to_numpy())

main()
@Linyou
Copy link
Contributor

Linyou commented Oct 3, 2022

The methods from_numpy() and from_torch() are also broken too. Currently, all methods involving external arrays are not working, but they work fine if I switch to metal backend. The only way to transfer these external arrays to taichi is via the python scope.

import taichi as ti
import numpy as np
import torch

ti.init(arch=ti.vulkan)


a = ti.field(dtype=ti.f32, shape=(10,))

float32 = torch.ones(10, dtype=torch.float32)
print("float32: ", float32)

a.from_torch(float32)

for i in range(10):
    print("a: ", a[i])

@ti.kernel
def from_numpy(dst: ti.template(), src: ti.types.ndarray()):
    for I in ti.grouped(src):
        dst[I] = src[I]

def from_numpy_python(dst, src):
    for i in range(dst.shape[0]):
        dst[i] = src[i]

float32 = np.array([1.0]*10).astype(np.float32)

from_numpy(a, float32)

for i in range(10):
    print("a: ", a[i])

from_numpy_python(a, float32)

for i in range(10):
    print("a: ", a[i])

@bobcao3
Copy link
Collaborator

bobcao3 commented Oct 3, 2022

Sounds like an synchronization issue... Can you try to add a ti.sync() before and after kernels involving external arrays

@Linyou
Copy link
Contributor

Linyou commented Oct 4, 2022

I have tried ti.sync() but the code is still not working as expected @bobcao3

@strongoier strongoier self-assigned this Oct 14, 2022
@strongoier strongoier moved this from Untriaged to Todo in Taichi Lang Oct 14, 2022
@strongoier
Copy link
Contributor

I'll close this issue because #6295 is essentially talking about the same problem and we'll update our progress there.

Repository owner moved this from Todo to Done in Taichi Lang Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

4 participants