I am a very beginner in CUDA. Recently, I tried to test the feature [cudaLaunchCooperativeKernel]. When I wanted to access the argument I passed into the kernel, it turned out that the error [kernel launch failed with error "an illegal memory access was encountered"] happened.
I have tested to access the data in the normal kernel launching method(launched as the commented instruction), which executed normally. Does anything I misconfigure?
Thanks for anyone’s help!!!
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <cuda.h>
#include <cuda_runtime_api.h>
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
#include <cooperative_groups.h>
using namespace std;
using namespace cooperative_groups;
namespace cg = cooperative_groups;
__global__ void test(int* i){
printf("%d", *i);
}
int main(){
int *i;
cudaMallocManaged(&i, 4);
*i = 5;
void *kArgs[] = {i};
//test<<<1,1>>>(i);
auto a = cudaLaunchCooperativeKernel((void*)(test), 1, 1, kArgs) ;
cudaError_t cudaerr = cudaDeviceSynchronize();
if (cudaerr != cudaSuccess)
printf("kernel launch failed with error \"%s\".\n",
cudaGetErrorString(cudaerr));
}