예제 #1
0
        /// <summary>
        /// Tries to determine the PTX instruction set to use, based on the PTX
        /// architecture and installed Cuda drivers.
        /// </summary>
        /// <param name="architecture">The PTX architecture</param>
        /// <param name="installedDriverVersion">The Cuda driver version</param>
        /// <param name="minDriverVersion">The minimum driver version.</param>
        /// <param name="instructionSet">The instruction set (if any).</param>
        /// <returns>True, if the instruction set could be determined.</returns>
        public static bool TryGetInstructionSet(
            CudaArchitecture architecture,
            CudaDriverVersion installedDriverVersion,
            out CudaDriverVersion minDriverVersion,
            out CudaInstructionSet instructionSet)
        {
            instructionSet = default;
            var architectureMinDriverVersion = CudaDriverVersionUtils
                                               .GetMinimumDriverVersion(architecture);

            minDriverVersion = architectureMinDriverVersion;

            foreach (var supportedSet in PTXCodeGenerator.SupportedInstructionSets)
            {
                var instructionSetMinDriverVersion = CudaDriverVersionUtils.
                                                     GetMinimumDriverVersion(supportedSet);
                minDriverVersion =
                    architectureMinDriverVersion >= instructionSetMinDriverVersion
                    ? architectureMinDriverVersion
                    : instructionSetMinDriverVersion;
                if (installedDriverVersion >= minDriverVersion)
                {
                    instructionSet = supportedSet;
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Returns the PTX instruction set to use, based on the PTX architecture and
        /// installed CUDA drivers.
        /// </summary>
        /// <param name="architecture">The PTX architecture</param>
        /// <param name="installedDriverVersion">The CUDA driver version</param>
        /// <returns>The PTX instruction set</returns>
        public static PTXInstructionSet GetInstructionSet(
            PTXArchitecture architecture,
            CudaDriverVersion installedDriverVersion)
        {
            var architectureMinDriverVersion = CudaDriverVersionUtils
                                               .GetMinimumDriverVersion(architecture);
            var minDriverVersion = architectureMinDriverVersion;

            foreach (var instructionSet in PTXCodeGenerator.SupportedInstructionSets)
            {
                var instructionSetMinDriverVersion = CudaDriverVersionUtils.
                                                     GetMinimumDriverVersion(instructionSet);
                minDriverVersion =
                    architectureMinDriverVersion >= instructionSetMinDriverVersion
                    ? architectureMinDriverVersion
                    : instructionSetMinDriverVersion;
                if (installedDriverVersion >= minDriverVersion)
                {
                    return(instructionSet);
                }
            }

            throw new NotSupportedException(
                      string.Format(
                          RuntimeErrorMessages.NotSupportedDriverVersion,
                          installedDriverVersion,
                          minDriverVersion));
        }