简体   繁体   English

cudaStream_t有多大?

[英]How big is a cudaStream_t?

I have inherited some code that basically does stuff like this: 我继承了一些基本上做这样的事情的代码:

void *stream;
cudaStreamCreate((cudaStream_t *)&stream);

Looking at targets/x86_64-linux/driver_types.h for CUDA 8, I see: 查看CUDA 8的targets/x86_64-linux/driver_types.h ,我看到:

typedef __device_builtin__ struct CUStream_st *cudaStream_t;

As far as I understand it, the cast will work, but I worry about how future-proof this may be, and also if it is safe when the code is ported to ARM. 据我所知,演员阵容会有效,但我担心这可能是未来的证据,以及代码移植到ARM时是否安全。 How dangerous is the above code? 上面的代码有多危险? Does the __device_builtin__ affect anything? __device_builtin__会影响什么吗?

(Note: I plan to talk to the developer directly and tell them to use cudaStream_t throughout and #include <cuda_runtime.h> , so I am hoping to clarify the technical issues here.) (注意:我打算直接与开发人员交谈并告诉他们使用整个cudaStream_t#include <cuda_runtime.h> ,所以我希望在这里澄清技术问题。)

How big is a cudaStream_t ? cudaStream_tcudaStream_t

Like you've observed, 就像你观察到的那样,

typedef __device_builtin__ struct CUStream_st *cudaStream_t;

So it's a pointer, and has the size of a pointer, ie 64 bits on typical architectures today but different sizes on other architectures. 所以它是一个指针,并且具有指针的大小,即当今典型架构上的64位,但在其他架构上具有不同的大小。 But do you really need to utilize that information? 但你真的需要利用这些信息吗? I would guess not. 我猜不会。

As far as I understand it, the cast will work, but I worry about how future-proof this may be 根据我的理解,演员会工作,但我担心这可能是未来的证据

Then make it: 然后做到:

cudaStream_t stream;
cudaStreamCreate(&stream);

or use the C++'ish API wrappers , eg: 或使用C ++'ish API包装器 ,例如:

auto device = cuda::device::current::get();
auto stream = device.create_stream(cuda::stream::sync);

where that's abstracted away, and stream_t is a wrapper, not a pointer, anyway (caveat: I'm the author of the wrapper library.) 哪里被抽象掉了,而stream_t是一个包装器,而不是一个指针,无论如何(警告:我是包装器库的作者。)

What I'd worry about is not incompatibility, but rather avoiding invalid assumptions. 我担心的不是不兼容,而是避免无效的假设。 And, indeed, you should not assume cudaStream_t is a pointer - just treat it as something opaque. 事实上, 你不应该假设cudaStream_t是一个指针 - 只是将它视为不透明的东西。

and also if it is safe when the code is ported to ARM. 以及代码移植到ARM时是否安全。 How dangerous is the above code? 上面的代码有多危险?

It's dangerous, but not because of the porting, but like I said, because of the invalid assumption. 这很危险,但不是因为移植,而是像我说的那样,因为假设无效。 It would be less dangerous with, say, 比方说,它会不那么危险

static_assert(sizeof(void*) == sizeof(cudaStream_t),
    "Unexpected size of cudaStream_t - not the same as void *");

but why are you insisting on the void * , really? 但你为什么要坚持void * ,真的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM