Hi, I observed that when using cudaMemcpyFrom/ToSymbol
series of API, one pass the symbol by name (reference?) but if the same API is wrapped in some helper function, then one pass by pointer.
__constant__ int C;
namespace helper {
cudaError_t cudaMemcpyToSymbolAsync(const void* symbol,
const void* src,
size_t count,
size_t offset,
cudaMemcpyKind kind,
cudaStream_t stream) {
return ::cudaMemcpyToSymbolAsync(symbol, src, count, offset, kind, stream);
}
} // namespace helper
int main() {
cudaStream_t s = 0;
int h{10};
assert(cudaSuccess == cudaMemcpyToSymbolAsync(C, &h, sizeof(int), 0, cudaMemcpyHostToDevice, s));
assert(cudaSuccess == helper::cudaMemcpyToSymbolAsync(&C, &h, sizeof(int), 0, cudaMemcpyHostToDevice));
}
First it otherwise would not compile, because passing an int
for const void*
is disallowed.
Secondly, it is a interesting that the “target” pointer for the memcpy is a const*
.
How come C
can pass to a const void*
argument in the first case, but not the second case and we need to address-of- C
?