mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
FLACCL: Display platform and device used
This commit is contained in:
@@ -33,6 +33,9 @@ namespace CUETools.Codecs.FLACCL
|
|||||||
{
|
{
|
||||||
public class FLACCLWriterSettings : AudioEncoderSettings
|
public class FLACCLWriterSettings : AudioEncoderSettings
|
||||||
{
|
{
|
||||||
|
internal IntPtr m_platform = IntPtr.Zero;
|
||||||
|
internal IntPtr m_device = IntPtr.Zero;
|
||||||
|
|
||||||
public FLACCLWriterSettings()
|
public FLACCLWriterSettings()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
@@ -61,6 +64,37 @@ namespace CUETools.Codecs.FLACCL
|
|||||||
{
|
{
|
||||||
if (EncoderModeIndex < 0)
|
if (EncoderModeIndex < 0)
|
||||||
throw new Exception("unsupported encoder mode");
|
throw new Exception("unsupported encoder mode");
|
||||||
|
if (OpenCL.NumberOfPlatforms < 1)
|
||||||
|
throw new Exception("no opencl platforms found");
|
||||||
|
if (Platform == null)
|
||||||
|
m_platform = OpenCL.GetPlatform(0).PlatformID;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < OpenCL.NumberOfPlatforms; i++)
|
||||||
|
{
|
||||||
|
var platform = OpenCL.GetPlatform(i);
|
||||||
|
if (platform.Name.Equals(Platform, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
m_platform = platform.PlatformID;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_platform == IntPtr.Zero)
|
||||||
|
throw new Exception("unknown platform \"" + Platform + "\". Platforms available:" +
|
||||||
|
string.Join(", ", (new List<Platform>(OpenCL.GetPlatforms())).ConvertAll(p => "\"" + p.Name + "\"").ToArray()));
|
||||||
|
}
|
||||||
|
Platform = OpenCL.GetPlatform(m_platform).Name;
|
||||||
|
{
|
||||||
|
//var device = OpenCL.GetPlatform(m_platform).GetDevice(OpenCL.GetPlatform(m_platform).QueryDeviceIntPtr()[0]);
|
||||||
|
var devices = new List<Device>(OpenCL.GetPlatform(m_platform).QueryDevices((DeviceType)DeviceType));
|
||||||
|
var RequireImageSupport = true;
|
||||||
|
var RequiredExtensions = new List<string>();
|
||||||
|
devices.RemoveAll(d => (d.ImageSupport != true && RequireImageSupport) || !d.HasExtensions(RequiredExtensions.ToArray()));
|
||||||
|
if (devices.Count == 0)
|
||||||
|
throw new Exception("no OpenCL devices found that matched filter criteria");
|
||||||
|
m_device = devices[0].DeviceID;
|
||||||
|
Device = devices[0].Name;
|
||||||
|
}
|
||||||
SetDefaultValuesForMode();
|
SetDefaultValuesForMode();
|
||||||
if (Padding < 0)
|
if (Padding < 0)
|
||||||
throw new Exception("unsupported padding value " + Padding.ToString());
|
throw new Exception("unsupported padding value " + Padding.ToString());
|
||||||
@@ -166,6 +200,11 @@ namespace CUETools.Codecs.FLACCL
|
|||||||
[SRDescription(typeof(Properties.Resources), "DescriptionDeviceType")]
|
[SRDescription(typeof(Properties.Resources), "DescriptionDeviceType")]
|
||||||
public OpenCLDeviceType DeviceType { get; set; }
|
public OpenCLDeviceType DeviceType { get; set; }
|
||||||
|
|
||||||
|
//[TypeConverter(typeof(FLACCLWriterSettingsDeviceConverter))]
|
||||||
|
[SRDescription(typeof(Properties.Resources), "DescriptionDevice")]
|
||||||
|
[Browsable(false)]
|
||||||
|
public string Device { get; set; }
|
||||||
|
|
||||||
[DefaultValue(0)]
|
[DefaultValue(0)]
|
||||||
[SRDescription(typeof(Properties.Resources), "DescriptionCPUThreads")]
|
[SRDescription(typeof(Properties.Resources), "DescriptionCPUThreads")]
|
||||||
public int CPUThreads { get; set; }
|
public int CPUThreads { get; set; }
|
||||||
@@ -1717,25 +1756,7 @@ namespace CUETools.Codecs.FLACCL
|
|||||||
OCLMan.BuildOptions = "";
|
OCLMan.BuildOptions = "";
|
||||||
OCLMan.SourcePath = System.IO.Path.GetDirectoryName(GetType().Assembly.Location);
|
OCLMan.SourcePath = System.IO.Path.GetDirectoryName(GetType().Assembly.Location);
|
||||||
OCLMan.BinaryPath = System.IO.Path.Combine(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CUE Tools"), "OpenCL");
|
OCLMan.BinaryPath = System.IO.Path.Combine(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CUE Tools"), "OpenCL");
|
||||||
int platformId = 0;
|
OCLMan.CreateContext(OpenCL.GetPlatform(m_settings.m_platform).GetDevice(m_settings.m_device));
|
||||||
if (m_settings.Platform != null)
|
|
||||||
{
|
|
||||||
platformId = -1;
|
|
||||||
string platforms = "";
|
|
||||||
for (int i = 0; i < OpenCL.NumberOfPlatforms; i++)
|
|
||||||
{
|
|
||||||
var platform = OpenCL.GetPlatform(i);
|
|
||||||
platforms += " \"" + platform.Name + "\"";
|
|
||||||
if (platform.Name.Equals(m_settings.Platform, StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
{
|
|
||||||
platformId = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (platformId < 0)
|
|
||||||
throw new Exception("unknown platform \"" + m_settings.Platform + "\". Platforms available:" + platforms);
|
|
||||||
}
|
|
||||||
OCLMan.CreateDefaultContext(platformId, (DeviceType)m_settings.DeviceType);
|
|
||||||
|
|
||||||
this.framesPerTask = (int)OCLMan.Context.Devices[0].MaxComputeUnits * Math.Max(1, m_settings.TaskSize / channels);
|
this.framesPerTask = (int)OCLMan.Context.Devices[0].MaxComputeUnits * Math.Max(1, m_settings.TaskSize / channels);
|
||||||
|
|
||||||
@@ -1763,7 +1784,7 @@ namespace CUETools.Codecs.FLACCL
|
|||||||
"#define DEBUG\n" +
|
"#define DEBUG\n" +
|
||||||
#endif
|
#endif
|
||||||
(m_settings.DeviceType == OpenCLDeviceType.CPU ? "#define FLACCL_CPU\n" : "") +
|
(m_settings.DeviceType == OpenCLDeviceType.CPU ? "#define FLACCL_CPU\n" : "") +
|
||||||
"#define OPENCL_PLATFORM \"" + OpenCL.GetPlatform(platformId).Name + "\"\n" +
|
"#define OPENCL_PLATFORM \"" + OpenCL.GetPlatform(m_settings.m_platform).Name + "\"\n" +
|
||||||
"#define VENDOR_ID " + OCLMan.Context.Devices[0].VendorID + "\n" +
|
"#define VENDOR_ID " + OCLMan.Context.Devices[0].VendorID + "\n" +
|
||||||
m_settings.Defines + "\n";
|
m_settings.Defines + "\n";
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,10 @@ namespace CUETools.FLACCL.cmd
|
|||||||
Console.WriteLine("OpenCL Options:");
|
Console.WriteLine("OpenCL Options:");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.WriteLine(" --opencl-type <X> CPU or GPU, default GPU");
|
Console.WriteLine(" --opencl-type <X> CPU or GPU, default GPU");
|
||||||
Console.WriteLine(" --opencl-platform \"ATI Stream\", \"NVIDIA CUDA\", \"Intel(R) OpenCL\" etc");
|
var platforms = new List<string>();
|
||||||
|
foreach (var value in (new FLACCLWriterSettingsPlatformConverter()).GetStandardValues(null))
|
||||||
|
platforms.Add(value as string);
|
||||||
|
Console.WriteLine(" --opencl-platform <X> {0}", platforms.Count == 0 ? "No OpenCL platforms detected" : string.Join(", ", platforms.ConvertAll(s => "\"" + s + "\"").ToArray()));
|
||||||
Console.WriteLine(" --group-size # Set GPU workgroup size (64,128,256)");
|
Console.WriteLine(" --group-size # Set GPU workgroup size (64,128,256)");
|
||||||
Console.WriteLine(" --task-size # Set number of frames per multiprocessor, default 8");
|
Console.WriteLine(" --task-size # Set number of frames per multiprocessor, default 8");
|
||||||
Console.WriteLine(" --slow-gpu Some encoding stages are done on CPU");
|
Console.WriteLine(" --slow-gpu Some encoding stages are done on CPU");
|
||||||
@@ -225,10 +228,9 @@ namespace CUETools.FLACCL.cmd
|
|||||||
|
|
||||||
if (((input_file == "-" || Path.GetExtension(input_file) == ".flac") && output_file == null))
|
if (((input_file == "-" || Path.GetExtension(input_file) == ".flac") && output_file == null))
|
||||||
{
|
{
|
||||||
|
Usage();
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.WriteLine("Output file not specified.");
|
Console.WriteLine("Output file not specified.");
|
||||||
Console.WriteLine();
|
|
||||||
Usage();
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +248,8 @@ namespace CUETools.FLACCL.cmd
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Usage();
|
Usage();
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Input file \"{0}\" does not exist.", input_file);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,6 +276,7 @@ namespace CUETools.FLACCL.cmd
|
|||||||
output_file == "-" ? Console.OpenStandardOutput() :
|
output_file == "-" ? Console.OpenStandardOutput() :
|
||||||
output_file == "nul" ? new NullStream() : null,
|
output_file == "nul" ? new NullStream() : null,
|
||||||
settings);
|
settings);
|
||||||
|
settings = encoder.Settings as FLACCLWriterSettings;
|
||||||
encoder.FinalSampleCount = audioSource.Length;
|
encoder.FinalSampleCount = audioSource.Length;
|
||||||
if (stereo_method != null)
|
if (stereo_method != null)
|
||||||
encoder.StereoMethod = Flake.LookupStereoMethod(stereo_method);
|
encoder.StereoMethod = Flake.LookupStereoMethod(stereo_method);
|
||||||
@@ -306,6 +311,8 @@ namespace CUETools.FLACCL.cmd
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Filename : {0}", input_file);
|
Console.WriteLine("Filename : {0}", input_file);
|
||||||
Console.WriteLine("File Info : {0}kHz; {1} channel; {2} bit; {3}", audioSource.PCM.SampleRate, audioSource.PCM.ChannelCount, audioSource.PCM.BitsPerSample, TimeSpan.FromSeconds(audioSource.Length * 1.0 / audioSource.PCM.SampleRate));
|
Console.WriteLine("File Info : {0}kHz; {1} channel; {2} bit; {3}", audioSource.PCM.SampleRate, audioSource.PCM.ChannelCount, audioSource.PCM.BitsPerSample, TimeSpan.FromSeconds(audioSource.Length * 1.0 / audioSource.PCM.SampleRate));
|
||||||
|
Console.WriteLine("Platform : {0}", settings.Platform);
|
||||||
|
Console.WriteLine("Device : {0}", settings.Device);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool keepRunning = true;
|
bool keepRunning = true;
|
||||||
@@ -394,12 +401,12 @@ namespace CUETools.FLACCL.cmd
|
|||||||
settings.MaxPartitionOrder,
|
settings.MaxPartitionOrder,
|
||||||
settings.GPUOnly ? "GPU" : "CPU",
|
settings.GPUOnly ? "GPU" : "CPU",
|
||||||
encoder.OrdersPerWindow,
|
encoder.OrdersPerWindow,
|
||||||
(encoder.Settings as FLACCLWriterSettings).MaxLPCOrder,
|
settings.MaxLPCOrder,
|
||||||
encoder.MinPrecisionSearch,
|
encoder.MinPrecisionSearch,
|
||||||
encoder.MaxPrecisionSearch,
|
encoder.MaxPrecisionSearch,
|
||||||
encoder.Settings.BlockSize,
|
encoder.Settings.BlockSize,
|
||||||
encoder.VBRMode,
|
encoder.VBRMode,
|
||||||
(encoder.Settings as FLACCLWriterSettings).MaxFixedOrder - (encoder.Settings as FLACCLWriterSettings).MinFixedOrder + 1,
|
settings.MaxFixedOrder - settings.MinFixedOrder + 1,
|
||||||
encoder.DoConstant ? "c" : ""
|
encoder.DoConstant ? "c" : ""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user