8000 [REQ] Tile API function to convert between data types · Issue #683 · NVIDIA/warp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[REQ] Tile API function to convert between data types #683

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

Open
chaoming0625 opened this issue Apr 27, 2025 · 7 comments
Open

[REQ] Tile API function to convert between data types #683

chaoming0625 opened this issue Apr 27, 2025 · 7 comments
Assignees
Labels
feature request Request for something to be added
Milestone

Comments

@chaoming0625
Copy link

Here is what I want to do. But I do not know what's wrong with this kernel.

import warp
import numpy as np


@warp.kernel
def kernel(
    a: warp.array(dtype=bool),
    b: warp.array(dtype=float),
):
    data = warp.tile_load(a, TILE_SIZE)
    data0 = warp.untile(data)
    data1 = warp.where(data0, 1., 0.)
    data2 = warp.tile(data1)
    warp.tile_store(b, data2)


m = 128
TILE_SIZE = m


data_a = warp.array(np.random.rand(m) < 0.3, dtype=bool)
data_b = warp.array(np.zeros(m), dtype=float)

warp.launch_tiled(kernel, dim=[1], inputs=[data_a, data_b], block_dim=128)

print(data_b.numpy())
@chaoming0625 chaoming0625 added the question The issue author requires information label Apr 27, 2025
@chaoming0625
Copy link
Author

I also tried to use warp.tile_map by the following syntax. But it does not work.

@warp.func
def where(s):
  return warp.where(s, 1., 0.)

warp.tile_map(where, data)

This produce the error of inconsistent data type in warp.tile_map due to the mismatch of bool and float.

@daedalus5
Copy link
Contributor

Would this work?

import warp
import numpy as np

TILE_SIZE = 128


@warp.kernel
def kernel(
    a: warp.array(dtype=int),
    b: warp.array(dtype=float),
):
    data = warp.tile_load(a, TILE_SIZE)
    data0 = warp.untile(data)
    data1 = warp.where(data0, 1., 0.)
    data2 = warp.tile(data1)
    warp.tile_store(b, data2)


data_a = warp.array(np.random.rand(TILE_SIZE) < 0.3, dtype=int)
data_b = warp.array(np.zeros(TILE_SIZE), dtype=float)

warp.launch_tiled(kernel, dim=[1], inputs=[data_a, data_b], block_dim=128)

print(data_a.numpy())
print(data_b.numpy())

@chaoming0625
Copy link
Author

Your example is converting int to float. However, my example tried to convert bool to float. Is it possible to provide a general interface such as tile_asarray to convert the tiled data type?

@daedalus5
Copy link
Contributor

Yep, we'll add this to our list.

@chaoming0625
Copy link
Author
chaoming0625 commented May 9, 2025

Is it possible to provide such support as soon as possible? This is an urgent requirement for me. Thanks. 😍

Converting the data types of a tiled array may be a simple implementation. I think it should be in the requirements of release 1.8.0?

@chaoming0625
Copy link
Author

@shi-eric @daedalus5

@daedalus5
Copy link
Contributor

Sure, I can work on this next.

@shi-eric shi-eric changed the title [QUESTION] How to convert the data type of a tile? [REQ] How to convert the data type of a tile? May 9, 2025
@shi-eric shi-eric added feature request Request for something to be added and removed question The issue author requires information labels May 9, 2025
@shi-eric shi-eric added this to the 1.8.0 milestone May 9, 2025
@shi-eric shi-eric changed the title [REQ] How to convert the data type of a tile? [REQ] Tile API function to convert between data types May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for something to be added
Projects
None yet
Development

No branches or pull requests

3 participants
0