Re: [cfe-users] Operator new in CUDA kernels

2017-08-25 Thread Justin Lebar via cfe-users
Thank you for the bug report.  This looks like a real bug, we should
fix it.  I will add it to our list.

Sorry for the long delay in getting back to you -- I don't read the
mailing lists habitually, and just happened to do a search today that
showed me that I'd missed many emails I should have responded to.

-Justin

On Sun, Jun 18, 2017 at 4:11 PM, Ralph Kube via cfe-users
 wrote:
> Hi,
> I’m trying to port my CUDA project to clang. Thanks for the fantastic work,
> clang is a charm to work with.
>
> One problem however, maybe you guys can help me out.
>
> I need to allocate memory for a class in a CUDA kernel on the heap.
> So I created a myclass** in the host program, pass it to the kernel and 
> attempt to
> allocate with new. Works fine in nvcc, in clang I get the error
>
> [1] % clang++ -std=c++14 -o test_new_device test_new_device.cu 
> -L/Developer/NVIDIA/CUDA-8.0/lib -lcudart
> ptxas fatal   : Unresolved extern function '_Znwm'
> clang-4.0: error: ptxas command failed with exit code 255 (use -v to see 
> invocation)
>
> I’m on osx 10.12.5, using
> % clang++ --version
> clang version 4.0.0 (tags/RELEASE_400/final 297808)
> Target: x86_64-apple-darwin16.6.0
> Thread model: posix
>
> My analysis of the situation is:
> * :: operator new() gets resolved wrong and tries to call the host-side 
> malloc.
> * ptxas cannot resolve the invoked host-side malloc _Znwm as a device 
> function.
>
> So, is there a way to tell clang that ::operator new() in device function 
> should call
> the device version of malloc. As described here:
> http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#memory-allocation-and-lifetime
>
>
>
> Below is a minimal program that reproduces the error.
>
>
> #include 
> #include 
>
> class myclass
> {
> public:
> __host__ __device__ myclass(const double _data) : data(_data) {}
> __host__ __device__ ~myclass()
> {
> printf("Deleting myclass\n");
> }
> __host__ __device__ double get_data() const {return(data);}
>
> private:
> const double data;
> };
>
>
>
> __global__
> void init_myclass(myclass** mycs_ptr)
> {
> (*mycs_ptr) = new myclass(14.0);
> }
>
>
> __global__
> void access_myclass(myclass** mycs_ptr)
> {
> printf("I am using data with value = %f\n", (*mycs_ptr) -> get_data());
> }
>
> __global__
> void delete_myclass(myclass** mycs_ptr)
> {
> delete (*mycs_ptr);
> }
>
>
> int main(void)
> {
> myclass** myclass_ptr{nullptr};
>
>
> init_myclass<<<1, 1>>>(myclass_ptr);
>
> access_myclass<<<1, 1>>>(myclass_ptr);
>
> delete_myclass<<<1, 1>>>(myclass_ptr);
>
> return(0);
> }
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] How to tell Clang which version of CUDA to use ?

2017-08-28 Thread Justin Lebar via cfe-users
--cuda-path is the right flag to pass.  Strange it's not doing the
right thing for you.

Can you include the output of running the same command line with -v?

On Fri, Aug 18, 2017 at 3:55 AM, Jean-Loup Tastet via cfe-users
 wrote:
> Hi,
>
> I am trying to use Clang to compile CUDA device code. I followed the
> instructions in [1] and compiled the latest Clang trunk [2].
>
> However, my system has both CUDA 8.0 and 9.0 RC installed, in
> `/usr/local/cuda-{8.0,9.0}`. The default `/usr/local/cuda` is symlinked
> to `/usr/local/cuda-8.0`.
>
> Clang only supports version 8.0, however it seems to incorrectly pick
> version 9.0, even when manually specifying the `--cuda-path`. For
> instance, trying to compile a trivial CUDA program (with no kernel):
> ```
> $ cat main.cu
> #include 
> #include 
>
> int main(int argc, char* argv[])
> {
> std::cout << "Hello, World!" << std::endl;
> }
>
> $ clang++ -o main main.cu \
> --cuda-path=/usr/local/cuda-8.0 \
> -I/usr/local/cuda-8.0/include \
> -L/usr/local/cuda-8.0/lib64 \
> -lcudart_static -ldl -lrt -pthread
> ```
> generates the following error:
> ```
> /home/jtastet/.local/stow/llvm_gcc-
> 6.3/lib/clang/6.0.0/include/__clang_cuda_runtime_wrapper.h:66:2: error:
> "Unsupported CUDA version!"
> #error "Unsupported CUDA version!"
>  ^
> In file included from :1:
> In file included from /home/jtastet/.local/stow/llvm_gcc-
> 6.3/lib/clang/6.0.0/include/__clang_cuda_runtime_wrapper.h:169:
> /usr/local/cuda-9.0/targets/x86_64-
> linux/include/device_functions.hpp:218:10: error: reference to
> __device__ function '__nvvm_bar0_popc' in __host__ function
>   return __nvvm_bar0_popc(predicate);
>  ^
> /usr/local/cuda-9.0/targets/x86_64-
> linux/include/device_functions.hpp:218:10: note: '__nvvm_bar0_popc'
> declared here
> /usr/local/cuda-9.0/targets/x86_64-
> linux/include/device_functions.hpp:223:10: error: reference to
> __device__ function '__nvvm_bar0_and' in __host__ function
>   return __nvvm_bar0_and(predicate);
>  ^
> [...output truncated...]
> ```
> Note the reference to CUDA 9.0 in the path.
>
> Do you know how to tell Clang which version of CUDA to use ? Does it
> have to be specified at compile-time or as a command-line option ?
>
> Uninstalling CUDA 9.0 is not an option here, since I do not have
> privileged access to the machine.
>
> Thanks in advance for your help !
>
> Best regards,
> Jean-Loup Tastet
>
>
> [1] https://llvm.org/docs/CompileCudaWithLLVM.html
> [2] For reference, I compiled revision 311091 with the following
> configuration:
> ```
> cmake -G "Unix Makefiles" \
> -D CMAKE_INSTALL_PREFIX=/home/jtastet/.local/stow/llvm_gcc-6.3 \
> -D CMAKE_BUILD_TYPE=Release \
> -D GCC_INSTALL_PREFIX=/afs/cern.ch/sw/lcg/external/gcc/6.3/x86_64-
> centos7 \
> ..
> ```
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] How to tell Clang which version of CUDA to use ?

2017-09-05 Thread Justin Lebar via cfe-users
Sorry for the delayed response, just got back from vacation.

I just installed cuda 9 to /usr/local/cuda-9.0 and couldn't reproduce
this problem.  I also tried redirecting /usr/local/cuda to
/usr/local/cuda-9.0 and passing an explicit
--cuda-path=/usr/local/cuda-8.0, and things still worked as expected.

Very strange what you're seeing, although I believe there's a decent
chance it's a bug in clang.  Hopefully the -v output will be
revealing.

-Justin

On Tue, Aug 29, 2017 at 12:49 AM, Jean-Loup Tastet
 wrote:
> As a workaround, we have temporarily disabled the CUDA 9.0 install (by
> renaming its directory to /usr/local/_cuda-9.0). Now the program compiles as
> expected (I also recompiled Clang in the meantime).
>
> As soon as I manage to convince my sysadmin to enable CUDA 9.0 again, I will
> retry with the `-v` command-line option and post the output here.
>
> On Mon, 2017-08-28 at 11:42 -0700, Justin Lebar wrote:
>
> --cuda-path is the right flag to pass.  Strange it's not doing the
> right thing for you.
>
> Can you include the output of running the same command line with -v?
>
> On Fri, Aug 18, 2017 at 3:55 AM, Jean-Loup Tastet via cfe-users
>  wrote:
>
> Hi,
>
> I am trying to use Clang to compile CUDA device code. I followed the
> instructions in [1] and compiled the latest Clang trunk [2].
>
> However, my system has both CUDA 8.0 and 9.0 RC installed, in
> `/usr/local/cuda-{8.0,9.0}`. The default `/usr/local/cuda` is symlinked
> to `/usr/local/cuda-8.0`.
>
> Clang only supports version 8.0, however it seems to incorrectly pick
> version 9.0, even when manually specifying the `--cuda-path`. For
> instance, trying to compile a trivial CUDA program (with no kernel):
> ```
> $ cat main.cu
> #include 
> #include 
>
> int main(int argc, char* argv[])
> {
> std::cout << "Hello, World!" << std::endl;
> }
>
> $ clang++ -o main main.cu \
> --cuda-path=/usr/local/cuda-8.0 \
> -I/usr/local/cuda-8.0/include \
> -L/usr/local/cuda-8.0/lib64 \
> -lcudart_static -ldl -lrt -pthread
> ```
> generates the following error:
> ```
> /home/jtastet/.local/stow/llvm_gcc-
> 6.3/lib/clang/6.0.0/include/__clang_cuda_runtime_wrapper.h:66:2: error:
> "Unsupported CUDA version!"
> #error "Unsupported CUDA version!"
>  ^
> In file included from :1:
> In file included from /home/jtastet/.local/stow/llvm_gcc-
> 6.3/lib/clang/6.0.0/include/__clang_cuda_runtime_wrapper.h:169:
> /usr/local/cuda-9.0/targets/x86_64-
> linux/include/device_functions.hpp:218:10: error: reference to
> __device__ function '__nvvm_bar0_popc' in __host__ function
>   return __nvvm_bar0_popc(predicate);
>  ^
> /usr/local/cuda-9.0/targets/x86_64-
> linux/include/device_functions.hpp:218:10: note: '__nvvm_bar0_popc'
> declared here
> /usr/local/cuda-9.0/targets/x86_64-
> linux/include/device_functions.hpp:223:10: error: reference to
> __device__ function '__nvvm_bar0_and' in __host__ function
>   return __nvvm_bar0_and(predicate);
>  ^
> [...output truncated...]
> ```
> Note the reference to CUDA 9.0 in the path.
>
> Do you know how to tell Clang which version of CUDA to use ? Does it
> have to be specified at compile-time or as a command-line option ?
>
> Uninstalling CUDA 9.0 is not an option here, since I do not have
> privileged access to the machine.
>
> Thanks in advance for your help !
>
> Best regards,
> Jean-Loup Tastet
>
>
> [1] https://llvm.org/docs/CompileCudaWithLLVM.html
> [2] For reference, I compiled revision 311091 with the following
> configuration:
> ```
> cmake -G "Unix Makefiles" \
> -D CMAKE_INSTALL_PREFIX=/home/jtastet/.local/stow/llvm_gcc-6.3 \
> -D CMAKE_BUILD_TYPE=Release \
> -D GCC_INSTALL_PREFIX=/afs/cern.ch/sw/lcg/external/gcc/6.3/x86_64-
> centos7 \
> ..
> ```
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users