Ignore:
Timestamp:
Dec 10, 2010, 4:32:19 PM (11 years ago)
Author:
Sven Rech
Message:

it should be possible now to use more opencl devices simultaneously (can't test it, because I only have one).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r2189 r2194  
    255255
    256256            settings = new KeySearcherSettings(this, oclManager);
    257 
    258             if (OpenCL.NumberOfPlatforms == 0)
    259             {
    260                 settings.UseOpenCL = false;
    261             }
    262257           
    263258            QuickWatchPresentation = new QuickWatch();
     
    267262
    268263            settings.PropertyChanged += SettingsPropertyChanged;
    269             ((QuickWatch)QuickWatchPresentation).IsOpenCLEnabled = settings.UseOpenCL;
     264            ((QuickWatch)QuickWatchPresentation).IsOpenCLEnabled = (settings.DeviceSettings.Count(x => x.useDevice) > 0);
    270265
    271266            localBruteForceStopwatch = new Stopwatch();
     
    281276        {
    282277            ((QuickWatch)QuickWatchPresentation).IsP2PEnabled = settings.UsePeerToPeer;
    283             ((QuickWatch)QuickWatchPresentation).IsOpenCLEnabled = settings.UseOpenCL;
     278            ((QuickWatch)QuickWatchPresentation).IsOpenCLEnabled = (settings.DeviceSettings.Count(x => x.useDevice) > 0);
    284279            p2PQuickWatchPresentation.UpdateSettings(this, settings);
    285280        }
     
    388383            int bytesToUse = (int)parameters[7];
    389384            Stack threadStack = (Stack)parameters[8];
    390             bool useOpenCL = (bool)parameters[9];
     385            var openCLDeviceSettings = (KeySearcherSettings.OpenCLDeviceSettings)parameters[9];
    391386
    392387            KeySearcherOpenCLCode keySearcherOpenCLCode = null;
    393388            KeySearcherOpenCLSubbatchOptimizer keySearcherOpenCLSubbatchOptimizer = null;
    394             if (useOpenCL)
     389            if (openCLDeviceSettings != null)
    395390            {
    396391                keySearcherOpenCLCode = new KeySearcherOpenCLCode(this, encryptedData, sender, CostMaster, 256 * 256 * 256 * 16);
    397                 keySearcherOpenCLSubbatchOptimizer = new KeySearcherOpenCLSubbatchOptimizer(settings.OpenCLMode, oclManager.CQ[settings.OpenCLDevice].Device.MaxWorkItemSizes.Aggregate(1, (x, y) => (x * (int)y)) / 8);
     392                keySearcherOpenCLSubbatchOptimizer = new KeySearcherOpenCLSubbatchOptimizer(openCLDeviceSettings.mode,
     393                        oclManager.CQ[openCLDeviceSettings.index].Device.MaxWorkItemSizes.Aggregate(1, (x, y) => (x * (int)y)) / 8);
     394
    398395                ((QuickWatch)QuickWatchPresentation).Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    399396                {
     
    422419                        keyTranslator = ShareKeys(patterns, threadid, keysLeft, keyTranslator, threadStack);
    423420
    424                         if (!useOpenCL)         //CPU
     421                        if (openCLDeviceSettings == null)         //CPU
    425422                        {
    426423                            finish = BruteforceCPU(keyTranslator, sender, bytesToUse);
     
    434431                            catch (Exception)
    435432                            {
    436                                 useOpenCL = false;
     433                                openCLDeviceSettings.useDevice = false;
    437434                                ((QuickWatch)QuickWatchPresentation).Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    438435                                {
     
    447444                        int progress = keyTranslator.GetProgress();
    448445
    449                         if (!useOpenCL)
     446                        if (openCLDeviceSettings == null)
    450447                        {
    451448                            doneKeysArray[threadid] += progress;
     
    477474            BigInteger[] keycounterArray = (BigInteger[])parameters[4];
    478475            BigInteger[] keysLeft = (BigInteger[])parameters[5];
     476            var openCLDeviceSettings = (KeySearcherSettings.OpenCLDeviceSettings)parameters[9];
    479477            try
    480478            {
    481479                Kernel bruteforceKernel = keySearcherOpenCLCode.GetBruteforceKernel(oclManager, keyTranslator);
    482                
    483                 int deviceIndex = settings.OpenCLDevice;
     480
     481                int deviceIndex = openCLDeviceSettings.index;
    484482               
    485483                Mem userKey;
     
    11381136        private void StartThreads(IControlEncryption sender, int bytesToUse, KeyPattern.KeyPattern[] patterns, BigInteger[] doneKeysA, BigInteger[] openCLDoneKeysA, BigInteger[] keycounters, BigInteger[] keysleft, Stack threadStack)
    11391137        {
    1140             for (int i = 0; i < patterns.Length; i++)
     1138            //First start the opencl threads:
     1139            int i = 0;
     1140            foreach (var ds in settings.DeviceSettings)
     1141            {
     1142                if (ds.useDevice)
     1143                {
     1144                    WaitCallback worker = new WaitCallback(KeySearcherJob);
     1145                    doneKeysA[i] = new BigInteger();
     1146                    openCLDoneKeysA[i] = new BigInteger();
     1147                    keycounters[i] = new BigInteger();
     1148
     1149                    ThreadPool.QueueUserWorkItem(worker, new object[] { patterns, i, doneKeysA, openCLDoneKeysA, keycounters, keysleft, sender, bytesToUse, threadStack, ds });
     1150                    i++;
     1151                }
     1152            }
     1153
     1154            //Then the CPU threads:
     1155            for (; i < patterns.Length; i++)
    11411156            {
    11421157                WaitCallback worker = new WaitCallback(KeySearcherJob);
     
    11441159                openCLDoneKeysA[i] = new BigInteger();
    11451160                keycounters[i] = new BigInteger();
    1146                 bool useOpenCL = false;
    1147 
    1148                 if (settings.UseOpenCL && (i == patterns.Length - 1))     //Last thread is the OpenCL thread
    1149                     useOpenCL = true;
    1150 
    1151                 ThreadPool.QueueUserWorkItem(worker, new object[] { patterns, i, doneKeysA, openCLDoneKeysA, keycounters, keysleft, sender, bytesToUse, threadStack, useOpenCL });
     1161
     1162                ThreadPool.QueueUserWorkItem(worker, new object[] { patterns, i, doneKeysA, openCLDoneKeysA, keycounters, keysleft, sender, bytesToUse, threadStack, null });
    11521163            }
    11531164        }
     
    11561167        {
    11571168            int threads = settings.CoresUsed;
    1158             if (settings.UseOpenCL)
    1159                 threads++;
     1169            threads += settings.DeviceSettings.Count(x => x.useDevice);
    11601170
    11611171            if (threads < 1)
Note: See TracChangeset for help on using the changeset viewer.