Could windows 2012 R2 server install gtx 1050Ti and Tesla P4 two cards, and use cuda program to use these two cards together?

Hi all,
I am a newer in cuda development. I have a Dell server installed windows 2012 R2. And I installed two gpu cards in it. One is Tesla P4, and another is gtx 1050 Ti. I installed cuda toolkit and all cards can display in windows device manager. Also I can use cudaSetDevice(0) or cudaSetDevice(1) to use one of two cards independently. Now I write a program like blow model(just pseudo-code):

threadOneFun()
{
cudaError_t ret = cudaSetDevice(0);
if (ret != cudaSuccess)
{
return;
}

ret = cudaStreamCreateWithFlags(gStream, /*cudaStreamDefault*/cudaStreamNonBlocking);
if (ret != cudaSuccess)
{

	return;
}

    .....
    do_work() //using gStream

}

threadTwoFun()
{
CUresult ret = cuInit(0);
if (ret != CUDA_SUCCESS)
{
return false;
}

//initialize the CUDA device
int device = 1;
ret = cuDeviceGet(&mCuDevice, device);
if (ret != CUDA_SUCCESS)
{
	return false;
}

//Create a CUDA context
ret = cuCtxCreate(&mCuContext, CU_CTX_BLOCKING_SYNC, mCuDevice);
if (ret != CUDA_SUCCESS)
{
	mCuDevice = 0;

	return false;
}
    .....
    ret = cuStreamCreate(&mCuStream, CU_STREAM_NON_BLOCKING);
    .....
    do_decode_work() //using gStream

}

I have two thread, one use gtx 1050 Ti to decode video, and use another card Tesla P4 to use cuda runtime api to do some computing. Now in threadTwoFun thread function decode can work successfully. But in threadOneFun thread function, I debug when run to cudaStreamCreateWithFlags code, the program crash and report error in cuda.dll and access voilation address.
Could anyone tell me if this model is ok? and is there any problem using two cards in cuda? Thanks very much!!!