This project is read-only.

Call methods from windows form

Nov 30, 2012 at 4:22 AM
Edited Nov 30, 2012 at 4:41 AM

Gives error: TypeOf expressions are not supported

on CudafyModule km = CudafyTranslator.Cudafy(ePlatfrom.x86, eArchitecture.sm_11); // which is located in static class & static method.

if convert all static to non-static then gives error: Non-static methods are not supported

Nov 30, 2012 at 10:54 AM

 Can you show the code you are trying to CUDAfy?  It looks like you have a typeof within your kernel code.


Nov 30, 2012 at 12:13 PM

Code is same as simple_kernel_params.cs but it works when I'm calling from console. But from Form it gives errors...

Nov 30, 2012 at 12:21 PM

I really need to see the complete code, else I'm just speculating.

Nov 30, 2012 at 12:28 PM

 private void btn_Click(object sender, EventArgs e)        {     

thread = new Thread(new ThreadStart(proc));     

      thread.IsBackground = true;     



private void proc(){

  Stopwatch sw = new Stopwatch();       







public class Class1    {     

  static GPGPU gpu;     

  public static void init()        {     

      CudafyModule km = CudafyTranslator.Cudafy(ePlatform.x86, eArchitecture.sm_11);
            gpu = CudafyHost.GetDevice(CudafyModes.Target);            gpu.LoadModule(km); 



public static void f()        {
                   int c;       

    int[] dev_c = gpu.Allocate<int>(); // cudaMalloc one Int32         

  gpu.Launch().add(2, 7, dev_c); // or gpu.Launch(1, 1, "add", 2, 7, dev_c);     

      gpu.CopyFromDevice(dev_c, out c);
            Console.WriteLine("2 + 7 = {0}", c);       

    gpu.Launch().sub(2, 7, dev_c);           

gpu.CopyFromDevice(dev_c, out c);
            Console.WriteLine("2 - 7 = {0}", c);


public static void add(int a, int b, int[] c)        {       

    c[0] = a + b;       


    public static void sub(int a, int b, int[] c)        {   

        c[0] = a - b; 



    public static void print()        {     





Nov 30, 2012 at 2:16 PM

You have placed a Cudafy attribute on host side code.  This attribute should only be put on methods that will run on the GPU, i.e. add and sub.  Removing it from f( ) will do the trick.

Nov 30, 2012 at 3:09 PM
Edited Nov 30, 2012 at 3:10 PM

Thank you, it helped! Also

1. can you tell me about implementing brute force on GPU(how to distribute values on threads)?

2. Is that possible to call windows API(open documents, or check system info) from CUDA code function?

Nov 30, 2012 at 5:17 PM

1. In the great words used by work-shy authors the world over, such a discussion is beyond the scope of this thread.  As I say in the CudafyByExample project consult a book such as CUDA by Example to get the background on CUDA.  This is easily transferable to CUDAfy.

2. It's not possible and why would you want to?  These things reside on the CPU end.  If you need some basics to be known by all threads then you can have the CPU pass info to the GPU via constant memory, else just copy it into global and read into shared memory in the thread.  As I said CUDA is a big subject and CUDAfy does abstract much away.