private CUmodule LoadPtxWithLinker(int GPU, string ptxFileName, string additionalLinkDependencyPath)
        {
            var options = new CudaJitOptionCollection();
            var err     = new CudaJOErrorLogBuffer(1024);

            options.Add(new CudaJOLogVerbose(true));
            options.Add(err);

            try
            {
                CudaLinker linker = new CudaLinker(options);
                linker.AddFile(ptxFileName, CUJITInputType.PTX, null);
                // Add the requested additional library
                linker.AddFile(additionalLinkDependencyPath, CUJITInputType.Library, null);
                byte[] cubin = linker.Complete();

                return(m_contexts[GPU].LoadModulePTX(cubin));
            }
            catch (Exception e)
            {
                throw new CudaException($"CUDA JIT linker error {err.Value}", e);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.WriteLine("Please enter a numeric argument.");
            }
            else
            {
                System.Console.WriteLine(args[0]);

                ID   = Convert.ToInt32(args[0]);
                evt  = new EventWaitHandle(false, EventResetMode.AutoReset, "compileprocessevent" + args[0]);
                evt2 = new EventWaitHandle(false, EventResetMode.AutoReset, "compileprocessevent2" + args[0]);

                mmf = MemoryMappedFile.OpenExisting("compileprocess" + args[0]);
                var stream = mmf.CreateViewStream();


#if JIT
                var ctx = new CudaContext();
#endif
                byte[] arrLengthBytes = new byte[4];

                System.Console.WriteLine("Compiler process started...");
                while (true)
                {
                    if (!evt.WaitOne(4000))   /// wait for start signal
                    {
                        break;
                    }


                    //Read from shared mem

                    stream.Position = 0;
                    stream.Read(arrLengthBytes, 0, 4);
                    int arrLength = BitConverter.ToInt32(arrLengthBytes, 0);

                    byte[] srcBuffer = new byte[arrLength];
                    stream.Read(srcBuffer, 0, arrLength);
                    string src = GetString(srcBuffer);

                    stream.Position = 0;

                    //  - 1 -  Ptx Compile
                    byte[] ptx = srcToPtx(src);


                    //  - 2 -  JIT Compile
#if JIT
                    var cl = new CudaLinker();
                    cl.AddData(ptx, CUJITInputType.PTX, null, null);
                    ptx = cl.Complete();
#endif
                    // Write back to shared mem
                    stream.Write(BitConverter.GetBytes(ptx.Length), 0, 4);
                    stream.Write(ptx, 0, ptx.Length);
                    stream.Flush();


                    evt2.Set();   ///  signal the end of compilation
                }
            }
        }