mkl_test_util.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. import hypothesis.strategies as st
  9. from caffe2.proto import caffe2_pb2
  10. from caffe2.python import workspace
  11. from caffe2.python import hypothesis_test_util as hu
  12. cpu_do = hu.cpu_do
  13. gpu_do = hu.gpu_do
  14. mkl_do = caffe2_pb2.DeviceOption(device_type=caffe2_pb2.MKLDNN)
  15. device_options = hu.device_options + (
  16. [mkl_do] if workspace.C.has_mkldnn else [])
  17. def device_checker_device_options():
  18. return st.just(device_options)
  19. def gradient_checker_device_option():
  20. return st.sampled_from(device_options)
  21. gcs = dict(
  22. gc=gradient_checker_device_option(),
  23. dc=device_checker_device_options()
  24. )
  25. gcs_cpu_only = dict(gc=st.sampled_from([cpu_do]), dc=st.just([cpu_do]))
  26. gcs_gpu_only = dict(gc=st.sampled_from([gpu_do]), dc=st.just([gpu_do]))
  27. gcs_mkl_only = dict(gc=st.sampled_from([mkl_do]), dc=st.just([mkl_do]))
  28. gcs_cpu_mkl = dict(gc=st.sampled_from([cpu_do, mkl_do]), dc=st.just([cpu_do, mkl_do]))