ID3D11Texture2D to uint8_t* use cuda faill

    auto imgz = 320;
    D3D11_TEXTURE2D_DESC desc;
    ZeroMemory(&desc, sizeof(D3D11_TEXTURE2D_DESC));
    desc.Width = imgz;
    desc.Height = imgz;
    desc.MipLevels = 1;
    desc.ArraySize = 1;
    desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    desc.SampleDesc.Count = 1;
    desc.SampleDesc.Quality = 0;
    desc.Usage = D3D11_USAGE_DEFAULT; 
    desc.BindFlags = D3D11_BIND_RENDER_TARGET;
    desc.CPUAccessFlags = 0;
    desc.MiscFlags = 0;

    D3D11_SUBRESOURCE_DATA data;
    unsigned char* out = (unsigned char*)malloc(imgz * imgz * 4 * sizeof(unsigned char));
    for (int i = 0; i < imgz * imgz; i++) {
        out[i * 4 + 2] = 255;
    }
    data.pSysMem = out;
    data.SysMemPitch = imgz * 4;
    data.SysMemSlicePitch = 0;

    ID3D11Texture2D* StagingTexture;
    winrt::com_ptr<ID3D11DeviceContext> m_d3dContext;
    auto d3dDevice = CreateD3DDevice();
    auto dxgiDevice = d3dDevice.as<IDXGIDevice>();
    auto m_device = CreateDirect3DDevice(dxgiDevice.get());

    d3dDevice = GetDXGIInterfaceFromObject<ID3D11Device>(m_device);
    d3dDevice->GetImmediateContext(m_d3dContext.put());
    d3dDevice.get()->CreateTexture2D(&desc, &data, &StagingTexture);

    cudaGraphicsResource* CUDAResource;
    cudaArray* textPtr;
    uint8_t* gpuArr;
    CUDA_CHECK(cudaGraphicsD3D11RegisterResource(&CUDAResource, StagingTexture, cudaGraphicsRegisterFlagsNone));
    CUDA_CHECK(cudaGraphicsMapResources(1, &CUDAResource, 0));
        CUDA_CHECK(cudaGraphicsSubResourceGetMappedArray(&textPtr, CUDAResource, 0, 0));
        CUDA_CHECK(cudaMemcpyToArray(textPtr, 0, 0, gpuArr, sizeof(uint8_t) * imgz* imgz * 4, cudaMemcpyDeviceToDevice)); << error : invalid argument
    CUDA_CHECK(cudaGraphicsUnmapResources(1, &CUDAResource, 0));

cudaMemcpyToArray will show error : invalid argument
hope you can help me, thank you!

You might wish to study the CUDA sample codes that demonstrate D3D11 interop.