Thread migration API (mis)documentation

Hi,

sorry for yet another nuisance about my experiences with the thread migration API, but i’m now getting really puzzled :

Page 118 of the reference manual, one can find that :

“If successful, cuCtxPopCurrent() passes back the context handle in *pctx. The context may then be made current to a different CPU thread by calling cuCtxPushCurrent().”

But using a single context, and poping it returns a NULL pointer (this is the case in the SDK thread migration example for instance). So there is obviously something wrong here… either in the documentation (for instance if the returned context is a pointer to the top of the context stack, ie. the context that was made current by poping), or in the implementation.

All these context stuff are pretty new, and i’m pretty sure not many people have tested them for now, but contexts are certainly a major improvement in CUDA 2.0 imho, so it would be great if they were working properly, or if they were properly documented.

Thanks for you time !
Cédric

You did not explain why you are so sure there is something wrong. How do you know that NULL is an invalid context pointer? And what did the cuCtxCreate return, NULL too or something else?

I’d be kind of surprised if a NULL context was valid, but that’s just being pragmatic, not a proper reason i agree.

Well, (of course) i checked the error code first … now here is a dummy example of some code that does not seem to match the doc :

CUcontext ctx;

    CUcontext cuContext;

/* initialize CUDA and CUBLAS */

    status = cuInit(0);

    assert(!status);

status = cuCtxCreate(&cuContext, 0, 0);

    assert(!status);

printf("(MAIN) created contex %p\n", cuContext);

/* release the context */

    status = cuCtxPopCurrent(&ctx);

    printf("(MAIN) cuCtxPopCurrent returned %p\n", ctx);

    assert(!status);

This produces the following output :

(MAIN) created contex 0x630a70

(MAIN) cuCtxPopCurrent returned (nil)

So, the context that was create (and automatically attached) does not match the one that is returned. From the documentation, you would certainly expect this to work :

CUcontext ctx;

  cuCtxPopCurrent(&ctx);

  cuCtxPushCurrent(ctx); (from another thread, typically)

I’m not saying it is broken, i’m just saying this is really suspect :) Perhaps i’m doing some mistake somewhere (i’m certainly doing so), so i thought it’s worth asking for some clarification.

Thanks,

Cédric

I basically agree with you analysis/opinion, it does look wrong (or at least like bad design) to me too.

Did you try calling cuCtxCreate and see what cuCtxPopCurrent does then?

I think this stuff was discussed already somewhere here, but I do not remember any conclusion.