This project is read-only.

Could not find function 'kernel' in module.

Aug 22, 2012 at 10:46 AM
Edited Aug 22, 2012 at 12:52 PM

I am trying to run the CudafyByExample and I am getting CudafyHostException : Could not find function 'kernel' in module at the simple_kernel example. Does anyone know why?

Platform x86 - GeForce 9500GT - VS2010 C# - CUDA SDK 4.2

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Cudafy;
using Cudafy.Host;
using Cudafy.Translator;

namespace cudafy
{
    public partial class Form1 : Form
    {
        private static GPGPU _gpu;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            foreach (GPGPUProperties prop in CudafyHost.GetDeviceProperties(CudafyModes.Target, false))
            {
                textBox2.AppendText("--- General Information for device  ---\n");
                textBox2.AppendText("\r\nName:  " + prop.Name);
                textBox2.AppendText("\r\nCompute capability:  " + prop.Capability.Major + "." + prop.Capability.Minor);
                textBox2.AppendText("\r\nClock rate: " + prop.ClockRate);
                textBox2.AppendText("\r\nTotal global mem:  " + prop.TotalMemory);
                textBox2.AppendText("\r\nTotal constant Mem:  " + prop.TotalConstantMemory);
            }

                
            try
            {
                // This 'smart' method will Cudafy all members with the Cudafy attribute in the calling type (i.e. Program)
                CudafyModule km = CudafyTranslator.Cudafy(ePlatform.Auto, eArchitecture.sm_11, new Version(4, 0), true, typeof(Program));
                // If cudafying will not work for you (CUDA SDK + VS not set up right) then comment out above and
                // uncomment below. Remember to also comment out the Structs and 3D arrays region below.
                // CUDA 4.0 SDK must be installed and cl.exe (VC++ compiler) must be in path. If you are compiling for
                // x86 then 32-bit CUDA 4.0 must be installed (also on Windows 64-bit). 
                // For x64 then 64-bit CUDA 4.0 must be installed.
                //CudafyModule km = CudafyModule.Deserialize(typeof(Program).Name);

                // Get the first CUDA device and load our module
                _gpu = CudafyHost.GetDevice(CudafyModes.Target, 0);
                _gpu.LoadModule(km);

                #region Add two numbers on GPU
                // Next we will add together some numbers. First we need to allocate memory on GPU for result (one int).
                // Then we launch our method and then read our results back again.
                int result;
                int[] dev_result = _gpu.Allocate<int>();
                _gpu.Launch().add(2, 7, dev_result); // or gpu.Launch(1, 1, "add", 2, 7, dev_c);
                _gpu.CopyFromDevice(dev_result, out result);
                textBox1.AppendText("2 + 7 = " + result);
                Console.WriteLine("2 + 7 = {0}", result);
                //Debug.Assert(result == 9);
                #endregion
            }
            catch (CudafyLanguageException cle)
            {
                HandleException(cle);
            }
            catch (CudafyCompileException cce)
            {
                HandleException(cce);
            }
            catch (CudafyHostException che)
            {
                HandleException(che);
            }
            

        }
      

        private static void HandleException(Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        [Cudafy]

        public static void add(int a, int b, int[] c)
        {
            c[0] = a + b;
        }
    }

    
}

 

Thanks.

Aug 22, 2012 at 3:05 PM

Looks like you've tried to cudafy class Program instead of Form1. 

                CudafyModule km = CudafyTranslator.Cudafy(ePlatform.Auto, eArchitecture.sm_11, new Version(4, 0), true, typeof(Program));