|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# ***************************************************************************** |
| 3 | +# Copyright (c) 2016-2020, Intel Corporation |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions are met: |
| 8 | +# - Redistributions of source code must retain the above copyright notice, |
| 9 | +# this list of conditions and the following disclaimer. |
| 10 | +# - Redistributions in binary form must reproduce the above copyright notice, |
| 11 | +# this list of conditions and the following disclaimer in the documentation |
| 12 | +# and/or other materials provided with the distribution. |
| 13 | +# |
| 14 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 18 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 24 | +# THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | +# ***************************************************************************** |
| 26 | + |
| 27 | +""" |
| 28 | +Container specific part of the DPNP |
| 29 | +
|
| 30 | +Notes |
| 31 | +----- |
| 32 | +This module contains code and dependency on diffrent containers used in DPNP |
| 33 | +
|
| 34 | +""" |
| 35 | + |
| 36 | + |
| 37 | +import dpnp.config as config |
| 38 | +from dpnp.dparray import dparray |
| 39 | + |
| 40 | +import numpy |
| 41 | + |
| 42 | + |
| 43 | +try: |
| 44 | + """ |
| 45 | + Detect DPCtl availability to use data container |
| 46 | + """ |
| 47 | + import dpctl.tensor as dpctl |
| 48 | + |
| 49 | + config.__DPNP_DPCTL_AVAILABLE__ = True |
| 50 | + |
| 51 | +except ImportError: |
| 52 | + """ |
| 53 | + No DPCtl data container available |
| 54 | + """ |
| 55 | + config.__DPNP_DPCTL_AVAILABLE__ = False |
| 56 | + |
| 57 | +# config.__DPNP_DPCTL_AVAILABLE__ = False |
| 58 | + |
| 59 | + |
| 60 | +__all__ = [ |
| 61 | + "create_output_container" |
| 62 | +] |
| 63 | + |
| 64 | + |
| 65 | +def create_output_container(shape, type): |
| 66 | + if config.__DPNP_OUTPUT_NUMPY__: |
| 67 | + """ Create NumPy ndarray """ |
| 68 | + # TODO need to use "buffer=" parameter to use SYCL aware memory |
| 69 | + result = numpy.ndarray(shape, dtype=type) |
| 70 | + elif config.__DPNP_DPCTL_AVAILABLE__: |
| 71 | + """ Create DPCTL array """ |
| 72 | + result = dpctl.usm_ndarray(shape, dtype=numpy.dtype(type).name) |
| 73 | + else: |
| 74 | + """ Create DPNP array """ |
| 75 | + result = dparray(shape, dtype=type) |
| 76 | + |
| 77 | + return result |
0 commit comments