This project is read-only.

Bug fix: Architectures 2.1 and 3.5 now handled by Translator

Oct 31, 2012 at 6:42 PM
Edited Oct 31, 2012 at 6:47 PM

I am not quite ready yet to do the source-code checkin myself, so if someone else cares to add these two small changes, it would be appreciated:

1) CudafyTranslator.cs - remove definition of GetComputeCapability and change line 71 to this

            CUDALanguage.ComputeCapability = arch.ComputeCapability();

2) Enumerator.cs - replace existing eArchitecture definition with this:

    /// <summary>
    /// CUDA Architecture
    /// </summary>
    public enum eArchitecture
    {
        /// <summary>Tesla 1.1</summary>
        sm_11,
        /// <summary>Tesla 1.2</summary>
        sm_12,
        /// <summary>Tesla 1.3</summary>
        sm_13,
        /// <summary>Fermi 2.0</summary>
        sm_20,
        /// <summary>Fermi 2.1</summary>
        sm_21,
        /// <summary>Kepler 3.0</summary>
        sm_30,
        /// <summary>Kepler 3.5</summary>
        sm_35
    }

       public static class ArchitectureExtensions {
          public static Version ComputeCapability(this eArchitecture @this) {
              switch (@this) {
                 case eArchitecture.sm_11: return new Version(1, 1);
                 case eArchitecture.sm_12: return new Version(1, 2);
                 case eArchitecture.sm_13: return new Version(1, 3);
                 case eArchitecture.sm_20: return new Version(2, 0);
                 case eArchitecture.sm_21: return new Version(2, 1);
                 case eArchitecture.sm_30: return new Version(3, 0);
                 case eArchitecture.sm_35: return new Version(3, 5);
                 default: 
                    if (Enum.IsDefined(typeof(eArchitecture), @this))
                       throw new ArgumentOutOfRangeException("eArchitecture", @this,
                          @"Code-out-of-date exception:
Handling for this eArchitecture value required in ArchitectureExtensions.ComputeCapability.");
                    else
                       throw new ArgumentOutOfRangeException("eArchitecture", @this, 
                          "Invalid eArchitecture value supplied to ArchitectureExtensions.ComputeCapability.");
                 }
              }

[edit] This change enables two additional versions: 2.1 and 3.5. I have tested the 2.1 change and it works nicely, providing a 12-15% performance improvement over the default specification. I am unable to test th 3.5 change with my current equipment.

Pieter

Oct 31, 2012 at 9:24 PM

While we are in this code, why not add this to ArchitectureExtensions also:

///<summary>Returns the minimum eArchitecture value that exceeds the Version capability.</summary>
public static eArchitecture GetArchitecture(this Version @this) { switch (@this.Major) { case 1: switch (@this.Minor) { case 1: return eArchitecture.sm_11; case 2: return eArchitecture.sm_12; case 3: default: return eArchitecture.sm_13; } case 2: switch (@this.Minor) { case 0: return eArchitecture.sm_20; case 1: default: return eArchitecture.sm_21; } case 3: switch (@this.Minor) { case 0: return eArchitecture.sm_30; case 5: default: return eArchitecture.sm_35; } default: return eArchitecture.sm_35; } }
Nov 1, 2012 at 5:10 AM
Edited Nov 1, 2012 at 5:14 AM
Actually, this unnecessarily (and undesirably!) exposes the (implementation) use by CUDA of System.Version. Better would be something like the code below, allowing a user specification such as:

 var gpu = CudafyHost.GetDevice(); 
 var km  = CudafyTranslator.Cudafy(ePlatform.x64, gpu.GetArcuitecture());
 gpu.LoadModule(km
);

 However, that requires adding references to the assembly Cudafy. Perhaps the enumeration eArchitecture is in in the wrong assembly, but it may be to late to change that.

Comments anyone?
-------------------------------------------------------------------------------------------

 ///<summary>Returns the minimum eArchitecture value that exceeds the Version capability.</summary>
public static eArchitecture GetArchitecture(this Cudafy.Host.GPGPU @this) {
   var arch = @this.GetDeviceProperties().Capability;
   switch (arch.Major) {
      case 1:
         switch (arch.Minor) {
            case 1: return eArchitecture.sm_11;
            case 2: return eArchitecture.sm_12;
            case 3:
            default: return eArchitecture.sm_13;
         }
      case 2:
         switch (arch.Minor) {
            case 0: return eArchitecture.sm_20;
            case 1:
            default: return eArchitecture.sm_21;
         }
      case 3:
         switch (arch.Minor) {
            case 0: return eArchitecture.sm_30;
            case 5:
            default: return eArchitecture.sm_35;
         }
      default: return eArchitecture.sm_35;
   }
}

Nov 1, 2012 at 5:17 AM

Aarrgh! my apologies for the formatting of the last post. When did  WYSIWYG  die and come back as Zombie-miniature-print?

Nov 1, 2012 at 7:28 PM
Edited Nov 1, 2012 at 7:32 PM

Looks like a good idea and I don't see any issues - CudafyTranslator already references Cudafy.  I will try and add this soon. Thanks also for the bug report - this has been fixed.