English 中文(简体)
为什么没有CUDA __device__ 归属作品的班级负责人? (C++)
原标题:Why defining class headers without CUDA __device__ attribute works? (C++)

我有一份载有以下声明的文件:

class Foo{
public:
    inline int getInt();
};

我的档案界定如下:

__device__ int Foo::getInt(){
   return 42;
}

这很麻烦,因为尽管我实际上不能打电话到<代码>。 东道方的Int,我可以将h文档列入.cpp文档中,因此,我对东道方的类型申报是显而易见的。 但是,对我来说,似乎没有工作了,因此,我为什么急切需要将<条码>__device__的属性放在.上?

最佳回答

如果它发挥作用,它就不应。 这可能是《世界人权宣言》汇编者的一个ug子,今后可能固定下来——因此并不依赖。

但是,如果您希望东道国(和非加拿大汇编者)能看到这一类别,但您有某种<条码>__device__功能,而您无需在东道国使用,则你总是能够将这些功能与<条码>编号>#ifdef __CUDACC__——<#endif合并。 <代码>CUDACC__在编篡时预先作了界定,否则就没有。 因此,你可以做如下写文章:

class Foo{
public:
#ifdef __CUDACC__
    inline __device__ int getInt();
#endif
};

If you are afraid of having too many preprocessor ifdefs, you can also do a trick as follows:

#ifdef __CUDACC__
#define HOST __host__
#define DEVICE __device__
#else
#define HOST
#define DEVICE
#endif

...

class Foo{
public:
    inline HOST DEVICE int getInt();
};
问题回答

修改如下:

__device__ int Foo::getInt(){
   return 42;
}

问题在于职能的返回类型。 缩略语 页: 1





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签