1 | ''' |
---|
2 | Created on Nov 29, 2016 |
---|
3 | |
---|
4 | @author: wpotrzebowski |
---|
5 | ''' |
---|
6 | |
---|
7 | import os |
---|
8 | import warnings |
---|
9 | |
---|
10 | import wx |
---|
11 | import wx.richtext |
---|
12 | import wx.lib.hyperlink |
---|
13 | |
---|
14 | from sas.sasgui.guiframe.documentation_window import DocumentationWindow |
---|
15 | |
---|
16 | class GpuOptions(wx.Dialog): |
---|
17 | """ |
---|
18 | "Acknowledgement" Dialog Box |
---|
19 | |
---|
20 | Shows the current method for acknowledging SasView in |
---|
21 | scholarly publications. |
---|
22 | |
---|
23 | """ |
---|
24 | |
---|
25 | def __init__(self, *args, **kwds): |
---|
26 | |
---|
27 | kwds["style"] = wx.DEFAULT_DIALOG_STYLE |
---|
28 | wx.Dialog.__init__(self, *args, **kwds) |
---|
29 | |
---|
30 | clinfo = self._get_clinfo() |
---|
31 | |
---|
32 | self.panel1 = wx.Panel(self, -1) |
---|
33 | static_box1 = wx.StaticBox(self.panel1, -1, "Available OpenCL Options:") |
---|
34 | |
---|
35 | boxsizer = wx.BoxSizer(orient=wx.VERTICAL) |
---|
36 | self.option_button = {} |
---|
37 | for index, clopt in enumerate(clinfo): |
---|
38 | button = wx.RadioButton(self.panel1, -1, label=clopt, name=clopt) |
---|
39 | button.SetValue(0) |
---|
40 | if clopt != "No OpenCL": |
---|
41 | self.option_button[clopt] = str(index) |
---|
42 | else: |
---|
43 | self.option_button[clopt] = "None" |
---|
44 | self.Bind(wx.EVT_RADIOBUTTON, self.on_radio, id=button.GetId()) |
---|
45 | boxsizer.Add(button, 0, 0) |
---|
46 | |
---|
47 | fit_hsizer = wx.StaticBoxSizer(static_box1, orient=wx.VERTICAL) |
---|
48 | fit_hsizer.Add(boxsizer, 0, wx.ALL, 5) |
---|
49 | |
---|
50 | self.panel1.SetSizer(fit_hsizer) |
---|
51 | |
---|
52 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
53 | self.vbox.Add(self.panel1, 0, wx.ALL, 10) |
---|
54 | |
---|
55 | accept_btn = wx.Button(self, wx.ID_OK) |
---|
56 | accept_btn.SetToolTipString("Accept OpenCL settings") |
---|
57 | |
---|
58 | help_btn = wx.Button(self, wx.ID_HELP, 'Help') |
---|
59 | help_btn.SetToolTipString("Help on the GPU options") |
---|
60 | |
---|
61 | self.Bind(wx.EVT_BUTTON, self.on_accept, accept_btn) |
---|
62 | self.Bind(wx.EVT_BUTTON, self.on_help, help_btn) |
---|
63 | self.Bind(wx.EVT_CLOSE, self.on_close) |
---|
64 | |
---|
65 | btn_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
66 | btn_sizer.Add((10, 20), 1) # stretchable whitespace |
---|
67 | btn_sizer.Add(accept_btn, 0) |
---|
68 | btn_sizer.Add((10, 20), 0) # non-stretchable whitespace |
---|
69 | btn_sizer.Add(help_btn, 0) |
---|
70 | |
---|
71 | # Add the button sizer to the main sizer. |
---|
72 | self.vbox.Add(btn_sizer, 0, wx.EXPAND|wx.ALL, 10) |
---|
73 | |
---|
74 | self.SetSizer(self.vbox) |
---|
75 | self.vbox.Fit(self) |
---|
76 | |
---|
77 | self.Centre() |
---|
78 | |
---|
79 | def _get_clinfo(self): |
---|
80 | clinfo = [] |
---|
81 | |
---|
82 | try: |
---|
83 | import pyopencl as cl |
---|
84 | for platform in cl.get_platforms(): |
---|
85 | for device in platform.get_devices(): |
---|
86 | clinfo.append(device.name) |
---|
87 | except ImportError: |
---|
88 | warnings.warn("pyopencl import failed. Please check installation") |
---|
89 | |
---|
90 | clinfo.append("No OpenCL") |
---|
91 | return clinfo |
---|
92 | |
---|
93 | def on_radio_default(self, event): |
---|
94 | event.GetEventObject().SetValue(not event.GetEventObject().GetValue()) |
---|
95 | |
---|
96 | def on_radio(self, event): |
---|
97 | """ |
---|
98 | Action triggered when button is selected |
---|
99 | :param event: |
---|
100 | :return: |
---|
101 | """ |
---|
102 | |
---|
103 | import sasmodels |
---|
104 | button = event.GetEventObject() |
---|
105 | os.environ["SAS_OPENCL"] = self.option_button[button.Name] |
---|
106 | sasmodels.kernelcl.ENV = None |
---|
107 | #Need to reload sasmodels.core module to account SAS_OPENCL = "None" |
---|
108 | reload(sasmodels.core) |
---|
109 | |
---|
110 | def on_accept(self, event): |
---|
111 | """ |
---|
112 | Close window on accpetance |
---|
113 | """ |
---|
114 | event.Skip() |
---|
115 | |
---|
116 | def on_help(self, event): |
---|
117 | """ |
---|
118 | Provide help on opencl options. |
---|
119 | """ |
---|
120 | TreeLocation = "user/gpu_computations.html" |
---|
121 | anchor = "#device-selection" |
---|
122 | DocumentationWindow(self, -1, |
---|
123 | TreeLocation, anchor, "OpenCL Options Help") |
---|
124 | |
---|
125 | def on_close(self, event): |
---|
126 | """ |
---|
127 | Close window |
---|
128 | """ |
---|
129 | event.Skip() |
---|