From: Karl R. <ru...@iu...> - 2014-01-09 13:07:41
|
Hi Chedy, this looks like an error in your build system (Makefile). Simple fix: Make sure you compile test.cpp *without* VIENNACL_WITH_CUDA defined, but keep VIENNACL_WITH_CUDA for blas3.cu Cleaner fix: Only put the forward declaration of RUN() into blas3.h, but move all ViennaCL-related includes to blas3.cu (or into a separate include file which gets included by blas3.cu only). It is important that the CUDA sources are only exposed to nvcc through source files with extension .cu, otherwise it interprets the code as native C++ code. Hope this helps :-) Best regards, Karli On 01/09/2014 01:35 PM, Chedy Raïssi wrote: > Hello everybody, > > I am currently trying to call a function that uses ViennaCL from a C++ > program (1 cpp file, 1 cu file and its associated header file). However, > even in a simple code (taken from blast3 benchmark code), nvcc/clang > returns a lot of weird errors. What am I doing wrong? > > Here is the current code and the errors : > > blas3.h > > #include <iostream> > > // > // ViennaCL includes > // > > #include "viennacl/scalar.hpp" > #include "viennacl/vector.hpp" > #include "viennacl/matrix.hpp" > #include "viennacl/linalg/prod.hpp" > #include "viennacl/matrix_proxy.hpp" > > #include "../../tutorial/Random.hpp" > > > #include "../benchmark-utils.hpp" > > int RUN(); > > > blas3.cu > /* ========================================================================= > Copyright (c) 2010-2012, Institute for Microelectronics, > Institute for Analysis and Scientific > Computing, > TU Wien. > Portions of this software are copyright by UChicago Argonne, LLC. > > ----------------- > ViennaCL - The Vienna Computing Library > ----------------- > > Project Head: Karl Rupp ru...@iu... > <mailto:ru...@iu...> > > > (A list of authors and contributors can be found in the PDF manual) > > License: MIT (X11), see file LICENSE in the base directory > ============================================================================= > */ > > /* > * > * Benchmark: BLAS level 3 functionality for dense matrices (blas3.cpp > and blas3.cu are identical, the latter being required for compilation > using CUDA nvcc) > * > */ > > > #include "blas3.h" > > #define BLAS3_MATRIX_SIZE 2048 > > template<typename ScalarType> > int run_benchmark() > { > Timer timer; > double exec_time; > > // > // One alternative: Put the matrices into a contiguous block of > memory (allows to use viennacl::fast_copy(), avoiding temporary memory) > // > std::vector<ScalarType> stl_A(BLAS3_MATRIX_SIZE * BLAS3_MATRIX_SIZE); > std::vector<ScalarType> stl_B(BLAS3_MATRIX_SIZE * BLAS3_MATRIX_SIZE); > std::vector<ScalarType> stl_C(BLAS3_MATRIX_SIZE * BLAS3_MATRIX_SIZE); > > // > // Fill the matrix > // > for (unsigned int i = 0; i < BLAS3_MATRIX_SIZE; ++i) > for (unsigned int j = 0; j < BLAS3_MATRIX_SIZE; ++j) > stl_A[i*BLAS3_MATRIX_SIZE + j] = random<ScalarType>(); > > for (unsigned int i = 0; i < BLAS3_MATRIX_SIZE; ++i) > for (unsigned int j = 0; j < BLAS3_MATRIX_SIZE; ++j) > stl_B[i + j*BLAS3_MATRIX_SIZE] = random<ScalarType>(); > > // > // Set up some ViennaCL objects > // > > viennacl::matrix<ScalarType> vcl_A(BLAS3_MATRIX_SIZE, BLAS3_MATRIX_SIZE); > viennacl::matrix<ScalarType> vcl_B(BLAS3_MATRIX_SIZE, BLAS3_MATRIX_SIZE); > viennacl::matrix<ScalarType> vcl_C(BLAS3_MATRIX_SIZE, BLAS3_MATRIX_SIZE); > > > > ///////////////////////////////////////////////// > //////////// Matrix-matrix products ///////////// > ///////////////////////////////////////////////// > > std::cout << " ------ Benchmark 1: Matrix-Matrix product ------ " << > std::endl; > > > > > viennacl::fast_copy(&(stl_A[0]), > &(stl_A[0]) + stl_A.size(), > vcl_A); > viennacl::fast_copy(&(stl_B[0]), > &(stl_B[0]) + stl_B.size(), > vcl_B); > vcl_C = viennacl::linalg::prod(vcl_A, vcl_B); > viennacl::backend::finish(); > timer.start(); > vcl_C = viennacl::linalg::prod(vcl_A, vcl_B); > viennacl::backend::finish(); > exec_time = timer.get(); > std::cout << " - Execution time on device (no setup time included): > " << exec_time << std::endl; > std::cout << " - GFLOPs (counting multiply&add as one operation): " > << (vcl_A.size1() / 1000.0) * (vcl_A.size2() / 1000.0) * (vcl_B.size2() > / 1000.0) / exec_time << std::endl; > std::cout << std::endl; > > return EXIT_SUCCESS; > } > > int RUN() > { > run_benchmark<float>(); > return 0; > } > > > and the test.cpp: > > #include "blas3.h" > > > int main(int argc, char **argv) > { > RUN(); > return0; > } > > > I am compiling on a Mac OS X 10.9.1 with clang and CUDA 5.5 installed: > > MacBook:test che$ make > [ 50%] *Building NVCC (Device) object > CMakeFiles/testGPU.dir//./testGPU_generated_blas3.cu.o* > clang: warning: argument unused during compilation: '-malign-double' > *Scanning dependencies of target testGPU* > [100%] Building CXX object CMakeFiles/testGPU.dir/test.cpp.o > In file included from > /Users/che/Downloads/ViennaCL-1.4.0/examples/benchmarks/test/test.cpp:1: > In file included from > /Users/che/Downloads/ViennaCL-1.4.0/examples/benchmarks/test/blas3.h:14: > In file included from /opt/local/include/viennacl/scalar.hpp:30: > In file included from > /opt/local/include/viennacl/linalg/scalar_operations.hpp:41: > */opt/local/include/viennacl/linalg/cuda/scalar_operations.hpp:96:20: > **error: **expected expression* > as_kernel<<<1, 1>>>(detail::cuda_arg<value_type>(s1), > * ^* > */opt/local/include/viennacl/linalg/cuda/scalar_operations.hpp:96:27: > **error: **expected expression* > as_kernel<<<1, 1>>>(detail::cuda_arg<value_type>(s1), > * ^* > */opt/local/include/viennacl/linalg/cuda/scalar_operations.hpp:220:22: > **error: **expected expression* > asbs_kernel<<<1, 1>>>(detail::cuda_arg<value_type>(s1), > * ^* > */opt/local/include/viennacl/linalg/cuda/scalar_operations.hpp:220:29: > **error: **expected expression* > asbs_kernel<<<1, 1>>>(detail::cuda_arg<value_type>(s1), > * ^* > */opt/local/include/viennacl/linalg/cuda/scalar_operations.hpp:348:24: > **error: **expected expression* > asbs_s_kernel<<<1, 1>>>(detail::cuda_arg<value_type>(s1), > * ^* > */opt/local/include/viennacl/linalg/cuda/scalar_operations.hpp:348:31: > **error: **expected expression* > asbs_s_kernel<<<1, 1>>>(detail::cuda_arg<value_type>(s1), > * ^* > In file included from > /Users/che/Downloads/ViennaCL-1.4.0/examples/benchmarks/test/test.cpp:1: > In file included from > /Users/che/Downloads/ViennaCL-1.4.0/examples/benchmarks/test/blas3.h:15: > In file included from /opt/local/include/viennacl/vector.hpp:32: > In file included from > /opt/local/include/viennacl/linalg/vector_operations.hpp:41: > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:68:31: > **error: **use of undeclared identifier 'blockDim'* > for (unsigned int i = blockDim.x * blockIdx.x + threadIdx.x; > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:68:44: > **error: **use of undeclared identifier 'blockIdx'* > for (unsigned int i = blockDim.x * blockIdx.x + threadIdx.x; > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:68:57: > **error: **use of undeclared identifier 'threadIdx'* > for (unsigned int i = blockDim.x * blockIdx.x + threadIdx.x; > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:70:32: > **error: **use of undeclared identifier 'gridDim'* > i += gridDim.x * blockDim.x) > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:70:44: > **error: **use of undeclared identifier 'blockDim'* > i += gridDim.x * blockDim.x) > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:93:31: > **error: **use of undeclared identifier 'blockDim'* > for (unsigned int i = blockDim.x * blockIdx.x + threadIdx.x; > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:93:44: > **error: **use of undeclared identifier 'blockIdx'* > for (unsigned int i = blockDim.x * blockIdx.x + threadIdx.x; > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:93:57: > **error: **use of undeclared identifier 'threadIdx'* > for (unsigned int i = blockDim.x * blockIdx.x + threadIdx.x; > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:95:32: > **error: **use of undeclared identifier 'gridDim'* > i += gridDim.x * blockDim.x) > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:95:44: > **error: **use of undeclared identifier 'blockDim'* > i += gridDim.x * blockDim.x) > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:126:20: > **error: **expected expression* > av_kernel<<<128, 128>>>(detail::cuda_arg<value_type>(vec1), > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:126:31: > **error: **expected expression* > av_kernel<<<128, 128>>>(detail::cuda_arg<value_type>(vec1), > * ^* > */opt/local/include/viennacl/linalg/cuda/vector_operations.hpp:173:31: > **error: **use of undeclared identifier 'blockDim'* > for (unsigned int i = blockDim.x * blockIdx.x + threadIdx.x; > * ^* > *fatal error: **too many errors emitted, stopping now [-ferror-limit=]* > 20 errors generated. > make[2]: *** [CMakeFiles/testGPU.dir/test.cpp.o] Error 1 > make[1]: *** [CMakeFiles/testGPU.dir/all] Error 2 > make: *** [all] Error 2 > > > Thank you very much ! > Chedy > > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk > > > > _______________________________________________ > ViennaCL-support mailing list > Vie...@li... > https://lists.sourceforge.net/lists/listinfo/viennacl-support > |