<jupyter_start><jupyter_text>Two Brains in My Laptop Center Processing Units (CPU)![](cpu.jpg)<jupyter_code># for linux, to see CPU info
!cat /proc/cpuinfo
# for OSX, it is
# !sysctl -a|grep machdep.cpu<jupyter_output>processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 142
model name	: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
stepping	: 9
microcode	: 0x62
cpu MHz		: 2700.000
cache size	: 3072 KB
physical id	: 0
siblings	: 4
core id		: 0
cpu cores	: 2
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 22
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 x[...]<jupyter_text>FLoating Point Operations Per Second (FLOPS)`CPU FLOPS = Number of Cores ∗ Average frequency ∗ Operations per cycle` single-precision floating point operations$+, -, *, /, \ldots$ operations of single-precision (32 bit) floating point numbers. operations per cycleInstruction Set Extensions of `Core i5-7200U`: Intel® SSE4.1, Intel® SSE4.2, Intel® AVX2For Advanced Vector Extensions 2 (AVX2), width of the **Single Instruction Multiple Data** (SIMD) register file is 256![](simd.png)<jupyter_code>operations_per_cycle = 256 / 32  # single precision (4 byte)
GFLOPS_CPU = 2 * 2.5 * operations_per_cycle
print('Theoretical computation power of my CPU = %s GFLOPS'%GFLOPS_CPU)<jupyter_output>Theoretical computation power of my CPU = 40.0 GFLOPS<jupyter_text>Graphics Processing Units (GPU)![](gpu.jpg)<jupyter_code>!nvidia-settings<jupyter_output>GPU at BusId 0x3c doesn't have a supported video decoder
** Message: PRIME: Requires offloading
** Message: PRIME: is it supported? yes<jupyter_text>`GPU FLOPS = Number of CUDA cores * 2 * Average frequency`<jupyter_code>GFLOPS_CPU = 384 * 2 * 1.189
print('Theoretical computation power of my GPU = %s GFLOPS'%GFLOPS_CPU)<jupyter_output>Theoretical computation power of my GPU = 913.152 GFLOPS<jupyter_text>A simple benchmarkMatrix multiplication test<jupyter_code>import torch

N = 1024
A = torch.randn(N, N)
B = torch.randn(N, N)
%timeit -n 100 C = A.mm(B)

# upload data to GPU, do the same calculation
AC = A.cuda()
BC = B.cuda()
%timeit -n 100 CC = AC.mm(BC)
# run only if you have an Nvidia graphic card, with driver properly configured
!nvidia-smi<jupyter_output>Wed Feb 14 21:52:24 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.25                 Driver Version: 390.25                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce 940MX       Off  | 00000000:3C:00.0 Off |                  N/A |
| N/A   83C    P0    N/A /  N/A |    972MiB /  2004MiB |    100%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memor[...]
{'fraction_non_alphanumeric': 0.17422867513611615, 'fraction_numerical': 0.04303863106040964, 'mean_word_length': 2.3991189427312776, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '382864', 'license': 'MIT', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1270, 'n_words': 403, 'path': 'gpu/hardware.ipynb', 'repo_name': 'GiggleLiu/marburg', 'size': '3857'}