Multithreading problem How to use cudaMemcpy() in a new thread?

I want to malloc some GPU memory in main thread,and in the a new sub thread ,do

    1: push the context data

    2: copy data from CPU to GPU using cudaMemcpy()

But ,when I successfully push the context ,there is something wrong with the cudaMemcpy() function.

It returns “cudaErrorInvalidDevicePointer”,which was allocated in main thread yet.

I am sorry for my pool english.

Thanks!