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

Cannot find reference 'encoding' in 'nerf_helper'.py'. #6

Closed
ZZy129326999 opened this issue Jul 13, 2022 · 10 comments
Closed

Cannot find reference 'encoding' in 'nerf_helper'.py'. #6

ZZy129326999 opened this issue Jul 13, 2022 · 10 comments

Comments

@ZZy129326999
Copy link

ZZy129326999 commented Jul 13, 2022

Dear export, hello! I want to learn about the details of "Cannot find reference 'encoding' in 'nerf_helper'.py'. ". I saw the description of pybind11 from CUDA EXTENSION. But there is a reference information "Cannot find reference 'encoding' in 'nerf_helper'.py'. " in model.py when running. Thank you very much!

model.py
from nerf_helper import encoding

nerf_extension.cu
PYBIND11_MODULE (TORCH_EXTENSION_NAME, nerf_helper)
{
  	nerf_helper.def ("comservativeSampling", &cudaSampler, conservative_sampler_docs.c_str());
  	nerf_helper.def ("sampling", &easySampler, sampler_docs.c_str());
	nerf_helper.def ("encoding", &positionalEncode, pe_docs.c_str());  // This !! Thank you !!!
	nerf_helper.def ("invTransformSample", &inverseTransformSample, inv_tf_docs.c_str());
	nerf_helper.def ("invTransformSamplePt", &inverseTransformSamplePt, inv_tf_pt_docs.c_str());
	nerf_helper.def ("imageSampling", &imageSampler, image_sampler_doc.c_str());
	nerf_helper.def ("validSampling", &validSampler, valid_sampler_doc.c_str());
}
@Enigmatisms
Copy link
Owner

There is no nerf_helper.py. nerf_helper as you see, is defined by setup.py in folder cuda/ (line 10). The module is called nerf_helper and it is already compiled, dynamically linked and loaded by your executable script. Therefore there is no python definition for encoding. Function encoding is "declared" in python, and defined in CUDA c++ (plz refer to file cuda/pe.cu). The definition is linked to the name encoding.

So, if python interpreter can not fine encoding, it might be (if I got it right):

  • You didn't correctly compile pytorch CUDA extension (follow README.md, running setup.py), so the interpreter had no where to find the definition of this function. Solution is to compile CUDA extension correctly (normally, successful compilation will result in .egg .dist(?maybe) files and it will tell you Finished ... (I don't remember) in the terminal).

@ZZy129326999
Copy link
Author

ZZy129326999 commented Jul 13, 2022

Thank you dear export!! I could generate nerf_helper.py after running cuda.

nerf_helper.py
def __bootstrap__():
    global __bootstrap__, __loader__, __file__
    import sys, pkg_resources, importlib.util
    __file__ = pkg_resources.resource_filename(__name__, 'nerf_helper.cpython-39-x86_64-linux-gnu.so')
    __loader__ = None; del __bootstrap__, __loader__
    spec = importlib.util.spec_from_file_location(__name__,__file__)
    mod = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(mod)
__bootstrap__()

Is this not normal? Thank you very much!

@Enigmatisms
Copy link
Owner

I set alias python = python3. Therefore, make sure you use python3.
My env: python 3.8 + Ubuntu 20.04, CUDA 11.3. Compilation does not yield nerf_helper.py. Normally, I think it would produce a .so (dynamic lib) file. Here are my terminal outputs:

  1. Trying to find nerf_helper related files (no nerf_helper.py):
    Screenshot 2022-07-14 010030
  2. python3 setup.py install --user output (last few lines):
    Screenshot 2022-07-14 005914
  3. after compilation: cuda/ folder structure:
    Screenshot 2022-07-14 010054

If you need further help, plz provide more implementation details like: how you use nerf_helper, how you load this module, how you compile CUDA extension and the environment of your device.

@ZZy129326999
Copy link
Author

图片
(9 line) Thank you very much!!!!

@ZZy129326999
Copy link
Author

ZZy129326999 commented Jul 13, 2022

I directly run setup.py with your method, I understand that cuda is not used in the project, but I am just curious why the compiled nerf_helper cannot retrieve the encoding. Thank you very much!

@Enigmatisms
Copy link
Owner

Well, it works for me even after checking out this older version and recompile:
Screenshot 2022-07-14 012316
Did you try importing this in a python shell? What does it output?

@ZZy129326999
Copy link
Author

图片
Wow! Does this mean it has!?

@Enigmatisms
Copy link
Owner

I think it does, but your IDE can never know its definition since it is loaded from .so. So if this does not occur during run-time and there is no further question, I will close this issue.

@ZZy129326999
Copy link
Author

Yes! Your code will not generate any errors during runtime! They are as good as you are! ! Thank you very much! You are a real export!!!!!

@Enigmatisms
Copy link
Owner

Thank you. That's a little overstating. Hope u can learn the things u want.

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