daniilidis-group / neural_renderer

A PyTorch port of the Neural 3D Mesh Renderer
Other
1.14k stars 254 forks source link

error: a value of type "const float *" cannot be used to initialize an entity of type "float *" #69

Closed erezposner closed 4 years ago

erezposner commented 5 years ago

Hi I get an error in the following code below saying I cannot init a value of type "const float " cannot be used to initialize an entity of type "float ".

For some reason input are consts. What could cause this issue? also the error is below thanks

code in rasterize.py line 249

 chainer.cuda.elementwise(
                'int32 _, raw float32 faces, raw float32 faces_inv',
                '',
                string.Template('''
                    /* face[v012][RGB] */
                    const int is = ${image_size};
                    const float* face = &faces[i * 9];
                    float* face_inv_g = &faces_inv[i * 9];

                    /* return if backside */
                    if ((face[7] - face[1]) * (face[3] - face[0]) < (face[4] - face[1]) * (face[6] - face[0]))
                        continue;

                    /* p[num][xy]: x, y is normalized from [-1, 1] to [0, is - 1]. */
                    float p[3][2];
                    for (int num = 0; num < 3; num++) for (int dim = 0; dim < 2; dim++)
                        p[num][dim] = 0.5 * (face[3 * num + dim] * is + is - 1);

                    /* compute face_inv */
                    float face_inv[9] = {
                        p[1][1] - p[2][1], p[2][0] - p[1][0], p[1][0] * p[2][1] - p[2][0] * p[1][1],
                        p[2][1] - p[0][1], p[0][0] - p[2][0], p[2][0] * p[0][1] - p[0][0] * p[2][1],
                        p[0][1] - p[1][1], p[1][0] - p[0][0], p[0][0] * p[1][1] - p[1][0] * p[0][1]};
                    float face_inv_denominator = (
                        p[2][0] * (p[0][1] - p[1][1]) +
                        p[0][0] * (p[1][1] - p[2][1]) +
                        p[1][0] * (p[2][1] - p[0][1]));
                    for (int k = 0; k < 9; k++) face_inv[k] /= face_inv_denominator;

                    /* set to global memory */
                    for (int k = 0; k < 9; k++) face_inv_g[k] = face_inv[k];
                ''').substitute(
                    image_size=self.image_size,
                ),
                'function',
            )(loop, self.faces, faces_inv)

and the error verbose

Drawing:   0%|          | 0/90 [00:00<?, ?it/s]Traceback (most recent call last):
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/cupy/cuda/compiler.py", line 242, in compile
    nvrtc.compileProgram(self.ptr, options)
  File "cupy/cuda/nvrtc.pyx", line 98, in cupy.cuda.nvrtc.compileProgram
  File "cupy/cuda/nvrtc.pyx", line 108, in cupy.cuda.nvrtc.compileProgram
  File "cupy/cuda/nvrtc.pyx", line 53, in cupy.cuda.nvrtc.check_status
cupy.cuda.nvrtc.NVRTCError: NVRTC_ERROR_COMPILATION (6)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/erez.posner/Repositories/neural_renderer-1.1.0/examples/example1.py", line 66, in <module>
    run()
  File "/home/erez.posner/Repositories/neural_renderer-1.1.0/examples/example1.py", line 52, in run
    images = renderer.render(vertices, faces, textures)  # [batch_size, RGB, image_size, image_size]
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/neural_renderer/renderer.py", line 106, in render
    self.background_color)
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/neural_renderer/rasterize.py", line 1002, in rasterize
    faces, textures, image_size, anti_aliasing, near, far, eps, background_color, True, False, False)['rgb']
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/neural_renderer/rasterize.py", line 942, in rasterize_rgbad
    image_size * 2, near, far, eps, background_color, return_rgb, return_alpha, return_depth)(*inputs)
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/chainer/function.py", line 233, in __call__
    ret = node.apply(inputs)
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/chainer/function_node.py", line 263, in apply
    outputs = self.forward(in_data)
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/chainer/function.py", line 135, in forward
    return self._function.forward(inputs)
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/chainer/function.py", line 340, in forward
    return self.forward_gpu(inputs)
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/neural_renderer/rasterize.py", line 493, in forward_gpu
    self.forward_face_index_map_gpu()
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/neural_renderer/rasterize.py", line 277, in forward_face_index_map_gpu
    )(loop, self.faces, faces_inv)
  File "cupy/core/_kernel.pyx", line 571, in cupy.core._kernel.ElementwiseKernel.__call__
  File "cupy/core/_kernel.pyx", line 593, in cupy.core._kernel.ElementwiseKernel._get_elementwise_kernel
  File "cupy/core/_kernel.pyx", line 402, in cupy.core._kernel._get_elementwise_kernel
  File "cupy/core/_kernel.pyx", line 40, in cupy.core._kernel._get_simple_elementwise_kernel
  File "cupy/core/_kernel.pyx", line 60, in cupy.core._kernel._get_simple_elementwise_kernel
  File "cupy/core/carray.pxi", line 166, in cupy.core.core.compile_with_cache
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/cupy/cuda/compiler.py", line 165, in compile_with_cache
    ptx = compile_using_nvrtc(source, options, arch, name + '.cu')
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/cupy/cuda/compiler.py", line 81, in compile_using_nvrtc
    ptx = prog.compile(options)
  File "/home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/cupy/cuda/compiler.py", line 246, in compile
    raise CompileException(log, self.src, self.name, options)
cupy.cuda.compiler.CompileException: /home/erez.posner/anaconda3/envs/pytorch/lib/python3.6/site-packages/cupy/core/include/cupy/carray.cuh(281): warning: statement is unreachable
          detected during instantiation of "void CIndexer<_ndim>::set(ptrdiff_t) [with _ndim=1]" 
/tmp/tmpxuw9wdwi/f7c31952d4daddd67431bd4fa6a19f38_2.cubin.cu(10): here

/tmp/tmpxuw9wdwi/f7c31952d4daddd67431bd4fa6a19f38_2.cubin.cu(16): error: a value of type "const float *" cannot be used to initialize an entity of type "float *"

1 error detected in the compilation of "/tmp/tmpxuw9wdwi/f7c31952d4daddd67431bd4fa6a19f38_2.cubin.cu".

Drawing:   0%|          | 0/90 [00:00<?, ?it/s]
cheiktraore commented 4 years ago

Hi @erezposner, have you been able to solve the problem ?

erezposner commented 4 years ago

never solved it. moved on to pytorch3d