We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Default GCP config for gpu_pcie_bandwidth is broken
When running the gpu_pcie_bandwidth benchmark under the default GCP config, the following error is raised: 
```
ERROR: (gcloud.compute.instances.create) Some requests did not succeed:
- Invalid value for field 'resource.disks[0].initializeParams.sourceImage': 'https://www.googleapis.com/compute/v1/projects/bionic-baton-343/global/images//ubuntu-os-cloud/ubuntu-1604-xenial-v20161115'. The URL is malformed.
```
Until a patch is released, this error can be avoided by running the benchmark and passing in the desired image and image project on the CLI, like so:

`./pkb.py --benchmarks=gpu_pcie_bandwidth --cloud=GCP --image=ubuntu-1610-yakkety-v20170307 --image_project=ubuntu-os-cloud`

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py`
Content:
```
1 # Copyright 2017 PerfKitBenchmarker Authors. All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #   http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 
16 """Runs NVIDIA's CUDA PCI-E bandwidth test
17       (https://developer.nvidia.com/cuda-code-samples)
18 """
19 
20 import numpy
21 import re
22 from perfkitbenchmarker import configs
23 from perfkitbenchmarker import flags
24 from perfkitbenchmarker import sample
25 from perfkitbenchmarker import regex_util
26 from perfkitbenchmarker.linux_packages import cuda_toolkit_8
27 
28 
29 flags.DEFINE_integer('gpu_pcie_bandwidth_iterations', 30,
30                      'number of iterations to run',
31                      lower_bound=1)
32 
33 
34 FLAGS = flags.FLAGS
35 
36 BENCHMARK_NAME = 'gpu_pcie_bandwidth'
37 # Note on the config: gce_migrate_on_maintenance must be false,
38 # because GCE does not support migrating the user's GPU state.
39 BENCHMARK_CONFIG = """
40 gpu_pcie_bandwidth:
41   description: Runs NVIDIA's CUDA bandwidth test.
42   flags:
43     gce_migrate_on_maintenance: False
44   vm_groups:
45     default:
46       vm_spec:
47         GCP:
48           image: /ubuntu-os-cloud/ubuntu-1604-xenial-v20161115
49           machine_type: n1-standard-4-k80x1
50           zone: us-east1-d
51           boot_disk_size: 200
52         AWS:
53           image: ami-a9d276c9
54           machine_type: p2.xlarge
55           zone: us-west-2b
56           boot_disk_size: 200
57         Azure:
58           image: Canonical:UbuntuServer:16.04.0-LTS:latest
59           machine_type: Standard_NC6
60           zone: eastus
61 """
62 BENCHMARK_METRICS = ['Host to device bandwidth',
63                      'Device to host bandwidth',
64                      'Device to device bandwidth']
65 
66 EXTRACT_BANDWIDTH_TEST_RESULTS_REGEX = r'\d+\s+(\d+\.?\d*)'
67 EXTRACT_DEVICE_INFO_REGEX = r'Device\s*(\d):\s*(.*$)'
68 
69 
70 def GetConfig(user_config):
71   config = configs.LoadConfig(BENCHMARK_CONFIG, user_config, BENCHMARK_NAME)
72   return config
73 
74 
75 def CheckPrerequisites(benchmark_config):
76   """Verifies that the required resources are present.
77 
78   Raises:
79     perfkitbenchmarker.data.ResourceNotFound: On missing resource.
80   """
81   cuda_toolkit_8.CheckPrerequisites()
82 
83 
84 def Prepare(benchmark_spec):
85   """Install CUDA toolkit 8.
86 
87   Args:
88     benchmark_spec: The benchmark specification. Contains all data that is
89         required to run the benchmark.
90   """
91   vm = benchmark_spec.vms[0]
92   vm.Install('cuda_toolkit_8')
93 
94 
95 def _ParseDeviceInfo(test_output):
96   """Parses the GPU device info from the CUDA device bandwidth test output.
97 
98   Args:
99     test_output: The resulting output string from the bandwidth
100       test application.
101 
102   Returns:
103     A dictionary mapping the device number to its name, for every
104     device available on the system.
105   """
106   matches = regex_util.ExtractAllMatches(EXTRACT_DEVICE_INFO_REGEX,
107                                          test_output, re.MULTILINE)
108   devices = {str(i[0]): str(i[1]) for i in matches}
109   return devices
110 
111 
112 def _ParseOutputFromSingleIteration(test_output):
113   """Parses the output of the CUDA device bandwidth test.
114 
115   Args:
116     test_output: The resulting output string from the bandwidth
117       test application.
118 
119   Returns:
120     A dictionary containing the following values as floats:
121       * the device to host bandwidth
122       * the host to device bandwidth
123       * the device to device bandwidth
124     All units are in MB/s, as these are the units guaranteed to be output
125     by the test.
126   """
127   matches = regex_util.ExtractAllMatches(EXTRACT_BANDWIDTH_TEST_RESULTS_REGEX,
128                                          test_output)
129   results = {}
130   for i, metric in enumerate(BENCHMARK_METRICS):
131     results[metric] = float(matches[i])
132   return results
133 
134 
135 def _CalculateMetricsOverAllIterations(result_dicts, metadata={}):
136   """Calculates stats given list of result dictionaries.
137 
138     Each item in the list represends the results from a single
139     iteration.
140 
141   Args:
142     result_dicts: a list of result dictionaries. Each result dictionary
143       represents a single run of the CUDA device bandwidth test,
144       parsed by _ParseOutputFromSingleIteration().
145 
146     metadata: metadata dict to be added to each Sample.
147 
148   Returns:
149     a list of sample.Samples containing the device to host bandwidth,
150     host to device bandwidth, and device to device bandwidth for each
151     iteration, along with the following stats for each bandwidth type:
152       * mean
153       * min
154       * max
155       * stddev
156   """
157   samples = []
158   for metric in BENCHMARK_METRICS:
159     sequence = [x[metric] for x in result_dicts]
160     # Add a Sample for each iteration, and include the iteration number
161     # in the metadata.
162     for idx, measurement in enumerate(sequence):
163       metadata_copy = metadata.copy()
164       metadata_copy['iteration'] = idx
165       samples.append(sample.Sample(
166           metric, measurement, 'MB/s', metadata_copy))
167 
168     samples.append(sample.Sample(
169         metric + ', min', min(sequence), 'MB/s', metadata))
170     samples.append(sample.Sample(
171         metric + ', max', max(sequence), 'MB/s', metadata))
172     samples.append(sample.Sample(
173         metric + ', mean', numpy.mean(sequence), 'MB/s', metadata))
174     samples.append(sample.Sample(
175         metric + ', stddev', numpy.std(sequence), 'MB/s', metadata))
176   return samples
177 
178 
179 def Run(benchmark_spec):
180   """Sets the GPU clock speed and runs the CUDA PCIe benchmark.
181 
182   Args:
183     benchmark_spec: The benchmark specification. Contains all data that is
184         required to run the benchmark.
185 
186   Returns:
187     A list of sample.Sample objects.
188   """
189   vm = benchmark_spec.vms[0]
190   # Note:  The clock speed is set in this function rather than Prepare()
191   # so that the user can perform multiple runs with a specified
192   # clock speed without having to re-prepare the VM.
193   cuda_toolkit_8.SetAndConfirmGpuClocks(vm)
194   num_iterations = FLAGS.gpu_pcie_bandwidth_iterations
195   raw_results = []
196   metadata = {}
197   metadata['num_iterations'] = num_iterations
198   metadata['num_gpus'] = cuda_toolkit_8.QueryNumberOfGpus(vm)
199   metadata['memory_clock_MHz'] = FLAGS.gpu_clock_speeds[0]
200   metadata['graphics_clock_MHz'] = FLAGS.gpu_clock_speeds[1]
201   run_command = ('%s/extras/demo_suite/bandwidthTest --device=all'
202                  % cuda_toolkit_8.CUDA_TOOLKIT_INSTALL_DIR)
203   for i in range(num_iterations):
204     stdout, _ = vm.RemoteCommand(run_command, should_log=True)
205     raw_results.append(_ParseOutputFromSingleIteration(stdout))
206     if 'device_info' not in metadata:
207       metadata['device_info'] = _ParseDeviceInfo(stdout)
208   return _CalculateMetricsOverAllIterations(raw_results, metadata)
209 
210 
211 def Cleanup(benchmark_spec):
212   """Uninstalls CUDA toolkit 8
213 
214   Args:
215     benchmark_spec: The benchmark specification. Contains all data that is
216         required to run the benchmark.
217   """
218   vm = benchmark_spec.vms[0]
219   vm.Uninstall('cuda_toolkit_8')
220
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py b/perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py
--- a/perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py
+++ b/perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py
@@ -45,7 +45,8 @@
     default:
       vm_spec:
         GCP:
-          image: /ubuntu-os-cloud/ubuntu-1604-xenial-v20161115
+          image: ubuntu-1604-xenial-v20161115
+          image_project: ubuntu-os-cloud
           machine_type: n1-standard-4-k80x1
           zone: us-east1-d
           boot_disk_size: 200

{"golden_diff": "diff --git a/perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py b/perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py\n--- a/perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py\n+++ b/perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py\n@@ -45,7 +45,8 @@\n     default:\n       vm_spec:\n         GCP:\n-          image: /ubuntu-os-cloud/ubuntu-1604-xenial-v20161115\n+          image: ubuntu-1604-xenial-v20161115\n+          image_project: ubuntu-os-cloud\n           machine_type: n1-standard-4-k80x1\n           zone: us-east1-d\n           boot_disk_size: 200\n", "issue": "Default GCP config for gpu_pcie_bandwidth is broken\nWhen running the gpu_pcie_bandwidth benchmark under the default GCP config, the following error is raised: \r\n```\r\nERROR: (gcloud.compute.instances.create) Some requests did not succeed:\r\n- Invalid value for field 'resource.disks[0].initializeParams.sourceImage': 'https://www.googleapis.com/compute/v1/projects/bionic-baton-343/global/images//ubuntu-os-cloud/ubuntu-1604-xenial-v20161115'. The URL is malformed.\r\n```\r\nUntil a patch is released, this error can be avoided by running the benchmark and passing in the desired image and image project on the CLI, like so:\r\n\r\n`./pkb.py --benchmarks=gpu_pcie_bandwidth --cloud=GCP --image=ubuntu-1610-yakkety-v20170307 --image_project=ubuntu-os-cloud`\n", "before_files": [{"content": "# Copyright 2017 PerfKitBenchmarker Authors. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#   http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\n\"\"\"Runs NVIDIA's CUDA PCI-E bandwidth test\n      (https://developer.nvidia.com/cuda-code-samples)\n\"\"\"\n\nimport numpy\nimport re\nfrom perfkitbenchmarker import configs\nfrom perfkitbenchmarker import flags\nfrom perfkitbenchmarker import sample\nfrom perfkitbenchmarker import regex_util\nfrom perfkitbenchmarker.linux_packages import cuda_toolkit_8\n\n\nflags.DEFINE_integer('gpu_pcie_bandwidth_iterations', 30,\n                     'number of iterations to run',\n                     lower_bound=1)\n\n\nFLAGS = flags.FLAGS\n\nBENCHMARK_NAME = 'gpu_pcie_bandwidth'\n# Note on the config: gce_migrate_on_maintenance must be false,\n# because GCE does not support migrating the user's GPU state.\nBENCHMARK_CONFIG = \"\"\"\ngpu_pcie_bandwidth:\n  description: Runs NVIDIA's CUDA bandwidth test.\n  flags:\n    gce_migrate_on_maintenance: False\n  vm_groups:\n    default:\n      vm_spec:\n        GCP:\n          image: /ubuntu-os-cloud/ubuntu-1604-xenial-v20161115\n          machine_type: n1-standard-4-k80x1\n          zone: us-east1-d\n          boot_disk_size: 200\n        AWS:\n          image: ami-a9d276c9\n          machine_type: p2.xlarge\n          zone: us-west-2b\n          boot_disk_size: 200\n        Azure:\n          image: Canonical:UbuntuServer:16.04.0-LTS:latest\n          machine_type: Standard_NC6\n          zone: eastus\n\"\"\"\nBENCHMARK_METRICS = ['Host to device bandwidth',\n                     'Device to host bandwidth',\n                     'Device to device bandwidth']\n\nEXTRACT_BANDWIDTH_TEST_RESULTS_REGEX = r'\\d+\\s+(\\d+\\.?\\d*)'\nEXTRACT_DEVICE_INFO_REGEX = r'Device\\s*(\\d):\\s*(.*$)'\n\n\ndef GetConfig(user_config):\n  config = configs.LoadConfig(BENCHMARK_CONFIG, user_config, BENCHMARK_NAME)\n  return config\n\n\ndef CheckPrerequisites(benchmark_config):\n  \"\"\"Verifies that the required resources are present.\n\n  Raises:\n    perfkitbenchmarker.data.ResourceNotFound: On missing resource.\n  \"\"\"\n  cuda_toolkit_8.CheckPrerequisites()\n\n\ndef Prepare(benchmark_spec):\n  \"\"\"Install CUDA toolkit 8.\n\n  Args:\n    benchmark_spec: The benchmark specification. Contains all data that is\n        required to run the benchmark.\n  \"\"\"\n  vm = benchmark_spec.vms[0]\n  vm.Install('cuda_toolkit_8')\n\n\ndef _ParseDeviceInfo(test_output):\n  \"\"\"Parses the GPU device info from the CUDA device bandwidth test output.\n\n  Args:\n    test_output: The resulting output string from the bandwidth\n      test application.\n\n  Returns:\n    A dictionary mapping the device number to its name, for every\n    device available on the system.\n  \"\"\"\n  matches = regex_util.ExtractAllMatches(EXTRACT_DEVICE_INFO_REGEX,\n                                         test_output, re.MULTILINE)\n  devices = {str(i[0]): str(i[1]) for i in matches}\n  return devices\n\n\ndef _ParseOutputFromSingleIteration(test_output):\n  \"\"\"Parses the output of the CUDA device bandwidth test.\n\n  Args:\n    test_output: The resulting output string from the bandwidth\n      test application.\n\n  Returns:\n    A dictionary containing the following values as floats:\n      * the device to host bandwidth\n      * the host to device bandwidth\n      * the device to device bandwidth\n    All units are in MB/s, as these are the units guaranteed to be output\n    by the test.\n  \"\"\"\n  matches = regex_util.ExtractAllMatches(EXTRACT_BANDWIDTH_TEST_RESULTS_REGEX,\n                                         test_output)\n  results = {}\n  for i, metric in enumerate(BENCHMARK_METRICS):\n    results[metric] = float(matches[i])\n  return results\n\n\ndef _CalculateMetricsOverAllIterations(result_dicts, metadata={}):\n  \"\"\"Calculates stats given list of result dictionaries.\n\n    Each item in the list represends the results from a single\n    iteration.\n\n  Args:\n    result_dicts: a list of result dictionaries. Each result dictionary\n      represents a single run of the CUDA device bandwidth test,\n      parsed by _ParseOutputFromSingleIteration().\n\n    metadata: metadata dict to be added to each Sample.\n\n  Returns:\n    a list of sample.Samples containing the device to host bandwidth,\n    host to device bandwidth, and device to device bandwidth for each\n    iteration, along with the following stats for each bandwidth type:\n      * mean\n      * min\n      * max\n      * stddev\n  \"\"\"\n  samples = []\n  for metric in BENCHMARK_METRICS:\n    sequence = [x[metric] for x in result_dicts]\n    # Add a Sample for each iteration, and include the iteration number\n    # in the metadata.\n    for idx, measurement in enumerate(sequence):\n      metadata_copy = metadata.copy()\n      metadata_copy['iteration'] = idx\n      samples.append(sample.Sample(\n          metric, measurement, 'MB/s', metadata_copy))\n\n    samples.append(sample.Sample(\n        metric + ', min', min(sequence), 'MB/s', metadata))\n    samples.append(sample.Sample(\n        metric + ', max', max(sequence), 'MB/s', metadata))\n    samples.append(sample.Sample(\n        metric + ', mean', numpy.mean(sequence), 'MB/s', metadata))\n    samples.append(sample.Sample(\n        metric + ', stddev', numpy.std(sequence), 'MB/s', metadata))\n  return samples\n\n\ndef Run(benchmark_spec):\n  \"\"\"Sets the GPU clock speed and runs the CUDA PCIe benchmark.\n\n  Args:\n    benchmark_spec: The benchmark specification. Contains all data that is\n        required to run the benchmark.\n\n  Returns:\n    A list of sample.Sample objects.\n  \"\"\"\n  vm = benchmark_spec.vms[0]\n  # Note:  The clock speed is set in this function rather than Prepare()\n  # so that the user can perform multiple runs with a specified\n  # clock speed without having to re-prepare the VM.\n  cuda_toolkit_8.SetAndConfirmGpuClocks(vm)\n  num_iterations = FLAGS.gpu_pcie_bandwidth_iterations\n  raw_results = []\n  metadata = {}\n  metadata['num_iterations'] = num_iterations\n  metadata['num_gpus'] = cuda_toolkit_8.QueryNumberOfGpus(vm)\n  metadata['memory_clock_MHz'] = FLAGS.gpu_clock_speeds[0]\n  metadata['graphics_clock_MHz'] = FLAGS.gpu_clock_speeds[1]\n  run_command = ('%s/extras/demo_suite/bandwidthTest --device=all'\n                 % cuda_toolkit_8.CUDA_TOOLKIT_INSTALL_DIR)\n  for i in range(num_iterations):\n    stdout, _ = vm.RemoteCommand(run_command, should_log=True)\n    raw_results.append(_ParseOutputFromSingleIteration(stdout))\n    if 'device_info' not in metadata:\n      metadata['device_info'] = _ParseDeviceInfo(stdout)\n  return _CalculateMetricsOverAllIterations(raw_results, metadata)\n\n\ndef Cleanup(benchmark_spec):\n  \"\"\"Uninstalls CUDA toolkit 8\n\n  Args:\n    benchmark_spec: The benchmark specification. Contains all data that is\n        required to run the benchmark.\n  \"\"\"\n  vm = benchmark_spec.vms[0]\n  vm.Uninstall('cuda_toolkit_8')\n", "path": "perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py"}], "after_files": [{"content": "# Copyright 2017 PerfKitBenchmarker Authors. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#   http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\n\"\"\"Runs NVIDIA's CUDA PCI-E bandwidth test\n      (https://developer.nvidia.com/cuda-code-samples)\n\"\"\"\n\nimport numpy\nimport re\nfrom perfkitbenchmarker import configs\nfrom perfkitbenchmarker import flags\nfrom perfkitbenchmarker import sample\nfrom perfkitbenchmarker import regex_util\nfrom perfkitbenchmarker.linux_packages import cuda_toolkit_8\n\n\nflags.DEFINE_integer('gpu_pcie_bandwidth_iterations', 30,\n                     'number of iterations to run',\n                     lower_bound=1)\n\n\nFLAGS = flags.FLAGS\n\nBENCHMARK_NAME = 'gpu_pcie_bandwidth'\n# Note on the config: gce_migrate_on_maintenance must be false,\n# because GCE does not support migrating the user's GPU state.\nBENCHMARK_CONFIG = \"\"\"\ngpu_pcie_bandwidth:\n  description: Runs NVIDIA's CUDA bandwidth test.\n  flags:\n    gce_migrate_on_maintenance: False\n  vm_groups:\n    default:\n      vm_spec:\n        GCP:\n          image: ubuntu-1604-xenial-v20161115\n          image_project: ubuntu-os-cloud\n          machine_type: n1-standard-4-k80x1\n          zone: us-east1-d\n          boot_disk_size: 200\n        AWS:\n          image: ami-a9d276c9\n          machine_type: p2.xlarge\n          zone: us-west-2b\n          boot_disk_size: 200\n        Azure:\n          image: Canonical:UbuntuServer:16.04.0-LTS:latest\n          machine_type: Standard_NC6\n          zone: eastus\n\"\"\"\nBENCHMARK_METRICS = ['Host to device bandwidth',\n                     'Device to host bandwidth',\n                     'Device to device bandwidth']\n\nEXTRACT_BANDWIDTH_TEST_RESULTS_REGEX = r'\\d+\\s+(\\d+\\.?\\d*)'\nEXTRACT_DEVICE_INFO_REGEX = r'Device\\s*(\\d):\\s*(.*$)'\n\n\ndef GetConfig(user_config):\n  config = configs.LoadConfig(BENCHMARK_CONFIG, user_config, BENCHMARK_NAME)\n  return config\n\n\ndef CheckPrerequisites(benchmark_config):\n  \"\"\"Verifies that the required resources are present.\n\n  Raises:\n    perfkitbenchmarker.data.ResourceNotFound: On missing resource.\n  \"\"\"\n  cuda_toolkit_8.CheckPrerequisites()\n\n\ndef Prepare(benchmark_spec):\n  \"\"\"Install CUDA toolkit 8.\n\n  Args:\n    benchmark_spec: The benchmark specification. Contains all data that is\n        required to run the benchmark.\n  \"\"\"\n  vm = benchmark_spec.vms[0]\n  vm.Install('cuda_toolkit_8')\n\n\ndef _ParseDeviceInfo(test_output):\n  \"\"\"Parses the GPU device info from the CUDA device bandwidth test output.\n\n  Args:\n    test_output: The resulting output string from the bandwidth\n      test application.\n\n  Returns:\n    A dictionary mapping the device number to its name, for every\n    device available on the system.\n  \"\"\"\n  matches = regex_util.ExtractAllMatches(EXTRACT_DEVICE_INFO_REGEX,\n                                         test_output, re.MULTILINE)\n  devices = {str(i[0]): str(i[1]) for i in matches}\n  return devices\n\n\ndef _ParseOutputFromSingleIteration(test_output):\n  \"\"\"Parses the output of the CUDA device bandwidth test.\n\n  Args:\n    test_output: The resulting output string from the bandwidth\n      test application.\n\n  Returns:\n    A dictionary containing the following values as floats:\n      * the device to host bandwidth\n      * the host to device bandwidth\n      * the device to device bandwidth\n    All units are in MB/s, as these are the units guaranteed to be output\n    by the test.\n  \"\"\"\n  matches = regex_util.ExtractAllMatches(EXTRACT_BANDWIDTH_TEST_RESULTS_REGEX,\n                                         test_output)\n  results = {}\n  for i, metric in enumerate(BENCHMARK_METRICS):\n    results[metric] = float(matches[i])\n  return results\n\n\ndef _CalculateMetricsOverAllIterations(result_dicts, metadata={}):\n  \"\"\"Calculates stats given list of result dictionaries.\n\n    Each item in the list represends the results from a single\n    iteration.\n\n  Args:\n    result_dicts: a list of result dictionaries. Each result dictionary\n      represents a single run of the CUDA device bandwidth test,\n      parsed by _ParseOutputFromSingleIteration().\n\n    metadata: metadata dict to be added to each Sample.\n\n  Returns:\n    a list of sample.Samples containing the device to host bandwidth,\n    host to device bandwidth, and device to device bandwidth for each\n    iteration, along with the following stats for each bandwidth type:\n      * mean\n      * min\n      * max\n      * stddev\n  \"\"\"\n  samples = []\n  for metric in BENCHMARK_METRICS:\n    sequence = [x[metric] for x in result_dicts]\n    # Add a Sample for each iteration, and include the iteration number\n    # in the metadata.\n    for idx, measurement in enumerate(sequence):\n      metadata_copy = metadata.copy()\n      metadata_copy['iteration'] = idx\n      samples.append(sample.Sample(\n          metric, measurement, 'MB/s', metadata_copy))\n\n    samples.append(sample.Sample(\n        metric + ', min', min(sequence), 'MB/s', metadata))\n    samples.append(sample.Sample(\n        metric + ', max', max(sequence), 'MB/s', metadata))\n    samples.append(sample.Sample(\n        metric + ', mean', numpy.mean(sequence), 'MB/s', metadata))\n    samples.append(sample.Sample(\n        metric + ', stddev', numpy.std(sequence), 'MB/s', metadata))\n  return samples\n\n\ndef Run(benchmark_spec):\n  \"\"\"Sets the GPU clock speed and runs the CUDA PCIe benchmark.\n\n  Args:\n    benchmark_spec: The benchmark specification. Contains all data that is\n        required to run the benchmark.\n\n  Returns:\n    A list of sample.Sample objects.\n  \"\"\"\n  vm = benchmark_spec.vms[0]\n  # Note:  The clock speed is set in this function rather than Prepare()\n  # so that the user can perform multiple runs with a specified\n  # clock speed without having to re-prepare the VM.\n  cuda_toolkit_8.SetAndConfirmGpuClocks(vm)\n  num_iterations = FLAGS.gpu_pcie_bandwidth_iterations\n  raw_results = []\n  metadata = {}\n  metadata['num_iterations'] = num_iterations\n  metadata['num_gpus'] = cuda_toolkit_8.QueryNumberOfGpus(vm)\n  metadata['memory_clock_MHz'] = FLAGS.gpu_clock_speeds[0]\n  metadata['graphics_clock_MHz'] = FLAGS.gpu_clock_speeds[1]\n  run_command = ('%s/extras/demo_suite/bandwidthTest --device=all'\n                 % cuda_toolkit_8.CUDA_TOOLKIT_INSTALL_DIR)\n  for i in range(num_iterations):\n    stdout, _ = vm.RemoteCommand(run_command, should_log=True)\n    raw_results.append(_ParseOutputFromSingleIteration(stdout))\n    if 'device_info' not in metadata:\n      metadata['device_info'] = _ParseDeviceInfo(stdout)\n  return _CalculateMetricsOverAllIterations(raw_results, metadata)\n\n\ndef Cleanup(benchmark_spec):\n  \"\"\"Uninstalls CUDA toolkit 8\n\n  Args:\n    benchmark_spec: The benchmark specification. Contains all data that is\n        required to run the benchmark.\n  \"\"\"\n  vm = benchmark_spec.vms[0]\n  vm.Uninstall('cuda_toolkit_8')\n", "path": "perfkitbenchmarker/linux_benchmarks/gpu_pcie_bandwidth_benchmark.py"}]}