This project is read-only.

Calling Cudafy in a WCF Service from a WCF Client

May 12, 2012 at 5:58 AM
Edited May 14, 2012 at 1:24 AM

Hi Nick

I have written a WCF service which uses my GTX480 to calculate and return an integer to a WCF Client using the service. The Cudafy code works fine during debugging in vs2010 but when I call the service from the client I get the following errors.

Error Message: Error decompiling <myKernel>

Inner Exception: Failed to resolve assembly Cudafy.NETat Mono.Cecil.BaseAssemblyResolver

Stack Trace: at ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody, at Cudafy.Translator.CUDAAstBuilder.CreateMethod

Obviously this is not the full dump which I can send if you need it but I was wondering if you had come up against this problem before and/or can recommend a solution.


EDIT: Further research into Mono has revealed that Mono does not support WSHttpBinding. I have written a simple test app which creates a service which calls Cudafy and uses BasicHttpBinding. This simple app is working. I'll do a test on the full blown app I need and let you know if this is still okay.


Many thanks in advance


Ian Carson

May 23, 2012 at 2:23 PM

Further possibly relevant info can be found in the CUDA C Programming Guide V4.1 under section 3.6 on p60. 

3.6 Tesla Compute Cluster Mode for Windows

Using NVIDIA’s System Management Interface (nvidia-smi), the Windows device driver can be put in TCC (Tesla Compute Cluster) mode for devices of the Tesla and Quadro Series of compute capability 2.0 and higher.This mode has the following primary benefits:

 It makes it possible to use these GPUs in cluster nodes with non‐NVIDIA integrated graphics;

 It makes these GPUs available via Remote Desktop, both directly and via cluster management systems that rely on Remote Desktop;

 It makes these GPUs available to applications running as a Windows service (i.e. in Session 0).

However, the TCC mode removes support for any graphics functionality.

Jun 9, 2012 at 8:34 PM

Hi Nick

Thanks for the followup. We are planning to build a Tesla Cluster to manage the scale of some of the computation we would like to do so your pointer will prove useful when we are at that point.

The kernel we have been discussing is working now over WCF. Security issues (of course :-) ) rather than GPU ones were the problem.

I thought you might be interested in another behaviour we were experiencing the other day. The Execute method we have written is called over WCF about once every 15 seconds. If the "standard"

            km3 = CudafyModule.TryDeserialize();

            if ((km3 == null) || !km3.TryVerifyChecksums())
                km3 = CudafyTranslator.Cudafy(eArchitecture.sm_20);

is used inside of the method the method fails after 14 or 15 calls with a GASS.CUDA.CUDAError Invalid context. We solved this by placing the above code into a separate Initialize() method which creates the CudafyModule as a separate static variable in the class which is passed into the LoadModule() method as required.

We tried to extract the

                var gpu3 = CudafyHost.GetDevice(CudafyModes.Target);

code into the Initialize() as well but this gave a CudafyHostException of Invalid Context so we had to leave it in the Execute() method.




Jun 11, 2012 at 7:38 AM

Hi Ian,

This exception is not unexpected.  The GetDevice method will on first call create a GPGPU instance and set the context to this instance.  Any GPU memory subsequently allocated is therefore associated with that context.  Whenever you then use or free this memory it must be on the same context as it was created on else you'll get invalid context errors.

We had been hoping to make the use of contexts transparent to the users but with demand for more complex multi-GPU set-ups and even multi-GPUs on one GPU card (GTX590 and 690) this is likely to not be possible.  We have internally a branch of the code that exposes some functionality for manually switching contexts and once reviewed and testing on legacy code is complete we'll release this. 

Best regards,