2 suggestions for better interface

Nov 3, 2012 at 5:29 AM
Edited Nov 3, 2012 at 5:32 AM

Hi Nick,

If yo haven't done the build and release yet, heer are two thoughts for enhancements:

  1. Add this line to dim3.cs for an implicit [edit]cast from int to dim3:
    public static implicit operator dim3(int dimX) { return new dim3(dimX); }
    
  2. Add these to GPGPU.cs (or perhaps to CudaGPGPU):
          public static void Safelaunch<T1>(this GPGPU @this, dim3 gridSize, dim3 blockSize, Action<GThread,T1> action, T1 t1) {
             @this.LaunchAsync(gridSize, blockSize, -1, action.Method.Name, 
                new object[] {t1});
          }
          public static void Safelaunch<T1,T2>(this GPGPU @this, dim3 gridSize, dim3 blockSize, 
             Action<GThread,T1,T2> action, T1 t1,T2 t2) 
          {
             @this.LaunchAsync(gridSize, blockSize, -1, action.Method.Name, 
                new object[] {t1,t2});
          }
          public static void Safelaunch<T1,T2,T3>(this GPGPU @this, dim3 gridSize, dim3 blockSize, 
             Action<GThread,T1,T2,T3> action, T1 t1,T2 t2,T3 t3) 
          {
             @this.LaunchAsync(gridSize, blockSize, -1, action.Method.Name, 
                new object[] {t1,t2,t3});
          }
          public static void Safelaunch<T1,T2,T3,T4>(this GPGPU @this, dim3 gridSize, dim3 blockSize, 
             Action<GThread,T1,T2,T3,T4> action, T1 t1,T2 t2,T3 t3,T4 t4) 
          {
             @this.LaunchAsync(gridSize, blockSize, -1, action.Method.Name, 
                new object[] {t1,t2,t3,t4});
          }
          #region etc. through to T14
          #endregion
          public static void Safelaunch<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>
             (this GPGPU @this, dim3 gridSize, dim3 blockSize, 
             Action<GThread,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> action, 
             T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8,T9 t9,T10 t10,T11 t11, T12 t12, T13 t13, T14 t14, T15 t15) 
          {
             @this.LaunchAsync(gridSize, blockSize, -1, action.Method.Name, 
                new object[] {t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15});
          }

[edit] The second adds type safety to the kernel Launch for up to 16 parameters (once the remaiing prototypes are typed in. I have tested both quickly on my TSP example, for a simple case, without problems.

Pieter

Coordinator
Nov 6, 2012 at 12:28 PM

Pieter,

I've added this into version control sources and added a unit test and put it into the ray tracing of CudafyByExample.  It's not as neat as dynamic but for safe code and for first launch speed it is a massive benefit.  Really great and likely to become my personal choice for launching kernels.

If you can give it a quick check over then I will get an official release out asap.

Cheers,

Nick

Nov 6, 2012 at 2:43 PM
Edited Nov 6, 2012 at 6:59 PM

Hi Nick,

 

That’s great! I have tested my TSP against the new build, and run both example programs with a build against a Dot Net 4/Release/X64 build. I had to build CudafyExamples twice, as it crapped out the first time in FinanceTest (or maybe the beginning of TimingTest), but that may have been my error; after I tweaked the configuration and built again it ran fine. I then ran both examples from a Dot Net 4/Release/Any CPU build, and both ran fine again.

 

You have now gutted the MyCudafy.cs file in the TSP example: all that is left in it is this extension method: (Hint hint)

namespace Cudafy.Host {

public static class GPGPUExtensions {
/// <summary>Returns the minimum defined Architecture enum exceeding the Device Compute Capability.</summary>

public static eArchitecture GetArchitecture(this GPGPU @this) {

var capability = @this.GetDeviceProperties().Capability;

switch (capability.Major) {

case 1:

switch (capability.Minor) {

case 1: return eArchitecture.sm_11;

case 2: return eArchitecture.sm_12;

case 3:

default: return eArchitecture.sm_13;

}

case 2:

switch (capability.Minor) {

case 0: return eArchitecture.sm_20;

case 1:

default: return eArchitecture.sm_21;

}

case 3:

switch (capability.Minor) {

case 0: return eArchitecture.sm_30;

case 5:

default: return eArchitecture.sm_35;

}

default: return eArchitecture.sm_35;

}

}
}
}

 

Yes, I know why the dynamic launcher is there, but I shy away from weakly-typed objects these days; too many past bad experiences probably. If I come up with any elegant ways to improve its type safety I will let you know.

 

Thank you also for the kind words, and reference, in regards to the TSP tuning example.

 

Regards,

 

Pieter Geerkens

 

 

 

From: NickKopp [email removed]
Sent: Tuesday, November 06, 2012 8:29 AM
To: email removed

Subject: Re: 2 suggestions for better interface [cudafy:401735]

 

From: NickKopp

Pieter,

I've added this into version control sources and added a unit test and put it into the ray tracing of CudafyByExample. It's not as neat as dynamic but for safe code and for first launch speed it is a massive benefit. Really great and likely to become my personal choice for launching kernels.

If you can give it a quick check over then I will get an official release out asap.

Cheers,

Nick

Coordinator
Nov 6, 2012 at 6:52 PM

Hi Pieter,

A slightly modified version has been added to GPGPU class.  

Nick