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

Kernel able to access variables which are not passed to the kernel launch #141

Closed
nithinsomu opened this issue Aug 17, 2023 · 1 comment
Closed

Comments

@nithinsomu
Copy link

I have observed that a variable which is defined outside the kernel and not passed to it either, is accessible by name within the kernel. Please check the code below

import warp as wp
import numpy as np
wp.init()

@wp.kernel
def calculations(J : int):
i = wp.tid()
wp.printf('\n p val is %d', p)

p= 10
J = 5
wp.launch(calculations, dim=1, inputs=[J])

Variable p is not being passed onto the kernel but when I run the code, the print statement gives the value of p that I have defined.
Is this an expected behavior or a bug?

@mmacklin
Copy link
Collaborator

Hi @nithinsomu, it is expected - this is mostly to support the case where you have some numeric constants in global scope that you would like to access in the kernel. Typically these should be declared with value = wp.constant(3.141) syntax (which will ensure that kernel caching etc works correctly).

Cheers,
Miles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants