device.py 1.3 KB
Newer Older
1
#   Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
D
dzhwinter 已提交
2
#
D
dzhwinter 已提交
3 4 5
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
D
dzhwinter 已提交
6
#
D
dzhwinter 已提交
7
#     http://www.apache.org/licenses/LICENSE-2.0
D
dzhwinter 已提交
8
#
D
dzhwinter 已提交
9 10 11 12 13
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Q
init  
qijun 已提交
14 15 16 17
"""
All util layers.
"""

18
from layer_function_generator import autodoc
Y
Yang Yu 已提交
19
from ..framework import unique_name
20
from ..layer_helper import LayerHelper
Q
init  
qijun 已提交
21 22 23 24

__all__ = ['get_places']


25
@autodoc()
Y
Yang Yu 已提交
26
def get_places(device_count=None, device_type=None):
Q
init  
qijun 已提交
27
    helper = LayerHelper('get_places', **locals())
Y
Yu Yang 已提交
28 29
    out_places = helper.create_variable(
        name=unique_name.generate(helper.name + ".out"))
Y
Yang Yu 已提交
30 31 32 33 34 35
    attrs = dict()
    if device_count is not None:
        attrs['device_count'] = int(device_count)
    if device_type is not None:
        attrs['device_type'] = str(device_type)

Q
init  
qijun 已提交
36
    helper.append_op(
Y
Yang Yu 已提交
37
        type='get_places', outputs={"Out": [out_places]}, attrs=attrs)
Q
init  
qijun 已提交
38 39

    return out_places