Caffe2 - Python API
A deep learning, cross platform ML framework
mkl_test_util.py
1 ## @package mkl_test_util
2 # Module caffe2.python.mkl_test_util
3 """
4 The MKL test utils is a small addition on top of the hypothesis test utils
5 under caffe2/python, which allows one to more easily test MKL related
6 operators.
7 """
8 
9 from __future__ import absolute_import
10 from __future__ import division
11 from __future__ import print_function
12 from __future__ import unicode_literals
13 
14 import hypothesis.strategies as st
15 
16 from caffe2.proto import caffe2_pb2
17 from caffe2.python import workspace
18 from caffe2.python import hypothesis_test_util as hu
19 
20 cpu_do = hu.cpu_do
21 gpu_do = hu.gpu_do
22 mkl_do = caffe2_pb2.DeviceOption(device_type=caffe2_pb2.MKLDNN)
23 device_options = hu.device_options + (
24  [mkl_do] if workspace.C.has_mkldnn else [])
25 
26 
27 def device_checker_device_options():
28  return st.just(device_options)
29 
30 
31 def gradient_checker_device_option():
32  return st.sampled_from(device_options)
33 
34 
35 gcs = dict(
36  gc=gradient_checker_device_option(),
37  dc=device_checker_device_options()
38 )
39 
40 gcs_cpu_only = dict(gc=st.sampled_from([cpu_do]), dc=st.just([cpu_do]))
41 gcs_gpu_only = dict(gc=st.sampled_from([gpu_do]), dc=st.just([gpu_do]))
42 gcs_mkl_only = dict(gc=st.sampled_from([mkl_do]), dc=st.just([mkl_do]))
43 
44 gcs_cpu_mkl = dict(gc=st.sampled_from([cpu_do, mkl_do]), dc=st.just([cpu_do, mkl_do]))