cuda Texture declaration compile-time error - cuda

I'm trying to compile the following piece of code:
#include <stdio.h>
#include <time.h>
#include <cuda.h>
#include <cuda_runtime_api.h>
texture<float, 2, cudaReadModeElementType> tex;
int main () { ... }
yet, nvcc gives me the following error:
main.c:6:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
I'm pretty new to CUDA, so I suppose I'm missing something here.

You can only use CUDA syntax in .cu files.

Related

c++ cuda-11.5 pcl-1.11 file_io.h(276): error: namespace "boost" has no member "numeric_cast" [duplicate]

System: cuda 11.3, gcc 7.5, boost 1.65.1, pcl 1.8.0
When I compile code that uses PCL library, it shows the following error
/usr/include/pcl-1.8/pcl/io/file_io.h(264): error: namespace "boost" has no member "numeric_cast"
/usr/include/pcl-1.8/pcl/io/file_io.h(264): error: type name is not allowed
/usr/include/pcl-1.8/pcl/io/file_io.h(280): error: namespace "boost" has no member "numeric_cast"
/usr/include/pcl-1.8/pcl/io/file_io.h(280): error: type name is not allowed
/usr/include/pcl-1.8/pcl/io/file_io.h(346): error: namespace "boost" has no member "iequals"
/usr/include/pcl-1.8/pcl/io/file_io.h(372): error: namespace "boost" has no member "iequals"
/usr/include/pcl-1.8/pcl/io/pcd_io.h(485): error: name followed by "::" must be a class or namespace name
/usr/include/pcl-1.8/pcl/io/pcd_io.h(493): error: name followed by "::" must be a class or namespace name
I looked into the file_io.h, found that the related code is <pcl/io/boost.h>. In this file, the header <boost/numeric/conversion/cast.hpp> contains the numeria_cast function, obviously this header is not included. Is this error related to the macro __CUDACC__? How do I solve this issue? /usr/include/pcl-1.8/pcl/io/boost.h is:
#ifndef _PCL_IO_BOOST_H_
#define _PCL_IO_BOOST_H_
#if defined __GNUC__
# pragma GCC system_header
#endif
#ifndef __CUDACC__
//https://bugreports.qt-project.org/browse/QTBUG-22829
#ifndef Q_MOC_RUN
#include <boost/version.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread.hpp>
#include <boost/thread/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/bind.hpp>
#include <boost/cstdint.hpp>
#include <boost/function.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/inherit.hpp>
#include <boost/mpl/inherit_linearly.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/algorithm/string.hpp>
#ifndef Q_MOC_RUN
#include <boost/date_time/posix_time/posix_time.hpp>
#endif
#if BOOST_VERSION >= 104700
#include <boost/chrono.hpp>
#endif
#include <boost/tokenizer.hpp>
#include <boost/foreach.hpp>
#include <boost/shared_array.hpp>
#include <boost/interprocess/sync/file_lock.hpp>
#if BOOST_VERSION >= 104900
#include <boost/interprocess/permissions.hpp>
#endif
#include <boost/iostreams/device/mapped_file.hpp>
#define BOOST_PARAMETER_MAX_ARITY 7
#include <boost/signals2.hpp>
#include <boost/signals2/slot.hpp>
#endif
#endif
#endif // _PCL_IO_BOOST_H_
Right, I solved it by using normal gcc compiler... DONT USE NVCC!

My C code won't compile against C code in a `.cu` file

I have 2 files that form a small CUDA library from my previous program (which works well, btw) written on C++.
The header for this library is:
#ifndef __cudaLU__
#define __cudaLU__
#include <assert.h>
#include <cuda_runtime.h>
#include <cusolverDn.h>
#include <cusolverSp.h>
#include <cusparse.h>
#include <cuComplex.h>
#include <stdlib.h>
void denseLS(int dim,
std::complex<float> * A,
std::complex<float> * b );
void sparseLS(int dim,
std::complex<float> *csrVal,
int *csrRowPtr,
int *csrColInd,
std::complex<float> *vecVal);
#endif
And I want to use this library in my old-as-the-hills C program just by setting procedure in the head of my main.c file:
extern void denseLS(int dim, float complex *A, float complex *b);
And it fails with a bunch of similar errors. Few of them are:
..NA/cudaLS.cu(115): error: namespace "std" has no member "complex"
..NA/cudaLS.cu(115): error: expected a ")"
..NA/cudaLS.cu(137): error: identifier "csrRowPtr" is undefined
..NA/cudaLS.cu(169): error: identifier "csrColInd" is undefined
..NA/cudaLS.cu(170): error: identifier "csrVal" is undefined
..NA/cudaLS.cu(171): error: identifier "vecVal" is undefined
I tried to make a change std::complex -> float complex and nothing works. Still same errors (without std error, ofc).
The cmake instructions file
cmake_minimum_required(VERSION 3.8)
project(NA)
set(CMAKE_C_STANDARD 11)
find_package(GSL REQUIRED)
find_package(CUDA REQUIRED)
include_directories("${CUDA_INCLUDE_DIRS}")
cuda_add_library(solvers STATIC
cudaLS.cu
cudaLS.h)
target_link_libraries(solvers ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cusolver_LIBRARY})
target_compile_features(solvers PUBLIC cxx_std_11)
set_target_properties( solvers
PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
add_executable(NA main.c)
set_target_properties(NA PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(NA PRIVATE GSL::gsl m solvers)
What am I doing wrong pals?
UPD:
g++/gcc - 7.3
Linux
Well, I found what exactly I did in a wrong way.
Cmake is OK. But headers in the .h file have to be modified to
extern "C" void denseLS(int dim, cuComplex *A, cuComplex *b );
The cuda functions in .c have to be decleared in the head (or separate .h-file) as
void denseLS(int dim, float complex *A, float complex *b);

undefined reference to cusolverDn

I am trying to run the cuSolver library available in cuda 7.0. I have an issue with using the cuSolver library that must be very simple to fix, but here I am asking for some help.
I have looked at quite a few examples posted around and I chose in particular this one from JackOLantern:
Parallel implementation for multiple SVDs using CUDA
I have just reduced it to a kernel_0.cu:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<stdio.h>
#include<assert.h>
#include<math.h>
#include <cusolverDn.h>
#include <cuda_runtime_api.h>
#include "Utilities.cuh"
/********/
/* MAIN */
/********/
int main(){
// --- gesvd only supports Nrows >= Ncols
// --- column major memory ordering
// --- cuSOLVE input/output parameters/arrays
int *devInfo; gpuErrchk(cudaMalloc(&devInfo, sizeof(int)));
// --- CUDA solver initialization
cusolverDnHandle_t solver_handle;
cusolverDnCreate(&solver_handle);
cusolverDnDestroy(solver_handle);
return 0;
}
I use the same Utilities.cuh and Utilities.cu as JackOlantern. I compile it as (to be explicit):
/usr/local/cuda-7.0/bin/nvcc kernel_0.cu Utilities.cu
And what I get is:
Utilities.cu(27): warning: conversion from a string literal to "char *" is deprecated
Utilities.cu(27): warning: conversion from a string literal to "char *" is deprecated
/tmp/tmpxft_00007e1d_00000000-22_kernel_0.o: In function `main':
tmpxft_00007e1d_00000000-4_kernel_0.cudafe1.cpp:(.text+0x3d): undefined reference to `cusolverDnCreate'
tmpxft_00007e1d_00000000-4_kernel_0.cudafe1.cpp:(.text+0x49): undefined reference to `cusolverDnDestroy'
collect2: error: ld returned 1 exit status
If I comment out the cusolverDnCreate and cusolverDnDestroy, it compiles fine, so the library is apparently well included.
What simple and basic point am I missing? I have searched around, but I could not fix it. Thanks there.
What simple and basic point am I missing?
You have to link against the cusolver library:
/usr/local/cuda-7.0/bin/nvcc kernel_0.cu Utilities.cu -lcusolver

C++ Builder STL for OS X fails?

Has anybody tried something as simple as #include <vector> in an application for the Mac compiled with XE2?
Is something so basic broken in XE2 update 1 for C++ Builder or is my install broken?
Simply adding #include <vector> to a new fire monkey HD app, I get build failures:
[BCC32 Error] cstdlib(43): E2015 Ambiguity between 'ldiv_t' and 'Posix::Stdlib::ldiv_t'
Full parser context
Unit1.cpp(7): #include C:\Program Files\Embarcadero\RAD Studio\9.0\include\boost_1_39\boost\tr1\tr1\vector
vector(16): #include C:\Program Files\Embarcadero\RAD Studio\9.0\include\boost_1_39\boost/tr1/detail/config_all.hpp
config_all.hpp(48): #include c:\program files\embarcadero\rad studio\9.0\include\dinkumware\cstdlib
cstdlib(32): namespace std
From the code:
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include "Unit1.h"
#include <vector>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
Solution from Embarcadero (this is for update 2 only):
Open cstdlib in the [RADStudioXE2]\include\dinkumware directory
Take line 49: using _CSTD size_t; using _CSTD div_t; using _CSTD ldiv_t;
Move it above the "#if defined" block right above it (line 33)
The STL can now be compiled into an FMX C++ application
try removing $(CG_BOOST_ROOT) from your include paths.

CUDA: Error while compiling my first cuda program

I am very new to CUDA programming.. I wrote my first code and when I compiled it, it is showing me a lots of error. Can anyone tell me what is wrong
the code
#include <stdio.h>
#include "cuda.h"
#include <stdlib.h>
__global__ void kernel(void) {
}
int main(int argc, char *argv[])
{
kernel<<<1,1>>>();
printf("finished \n");
return 0;
}
The errors are
cuda.c:5: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âvoidâ
cuda.c:7: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âvoidâ
cuda.c: In function âmainâ:
cuda.c:12: error: âkernelâ undeclared (first use in this function)
cuda.c:12: error: (Each undeclared identifier is reported only once
cuda.c:12: error: for each function it appears in.)
cuda.c:12: error: expected expression before â<â token
I compiled using
nvcc cuda.c
Can anyone tell me what mistake I am making....
nvcc runs .c files through the normal C compiler. Rename your file to cuda.cu.