CUDA unhandled exception

With help from Libtorch loss.backward(); C10 Error
I got the error description ‘CUDA error: device-side assert triggered’.
On CUDA Error: Device-Side Assert Triggered: Solved | Built In
it is described ‘caused by an inconsistency between the number of labels and output units or an incorrect input for a loss function’. So I checked my target tensor

auto target = torch::zeros(TRAIN_BATCH_SIZE, torch::kInt64).to(device);

Without cudaMemcpy there is no exception. The error was in

cudaMemcpy(&resdata[i * NET_OUTPUT_COUNT + j], &cvResult[imgcount], sizeof(int64_t), cudaMemcpyHostToDevice);