MCPcopy
hub / github.com/PaddlePaddle/PaddleOCR / check_device

Function check_device

tools/program.py:118–177  ·  view source on GitHub ↗

Log error and exit when set use_gpu=true in paddlepaddle cpu version.

(
    use_gpu,
    use_xpu=False,
    use_npu=False,
    use_mlu=False,
    use_gcu=False,
    use_iluvatar_gpu=False,
    use_metax_gpu=False,
)

Source from the content-addressed store, hash-verified

116
117
118def check_device(
119 use_gpu,
120 use_xpu=False,
121 use_npu=False,
122 use_mlu=False,
123 use_gcu=False,
124 use_iluvatar_gpu=False,
125 use_metax_gpu=False,
126):
127 """
128 Log error and exit when set use_gpu=true in paddlepaddle
129 cpu version.
130 """
131 err = (
132 "Config {} cannot be set as true while your paddle "
133 "is not compiled with {} ! \nPlease try: \n"
134 "\t1. Install paddlepaddle to run model on {} \n"
135 "\t2. Set {} as false in config file to run "
136 "model on CPU"
137 )
138
139 try:
140 if use_gpu and use_xpu:
141 print("use_xpu and use_gpu can not both be true.")
142 if use_gpu and not paddle.is_compiled_with_cuda():
143 print(err.format("use_gpu", "cuda", "gpu", "use_gpu"))
144 sys.exit(1)
145 if use_xpu and not paddle.device.is_compiled_with_xpu():
146 print(err.format("use_xpu", "xpu", "xpu", "use_xpu"))
147 sys.exit(1)
148 if use_npu:
149 if (
150 int(paddle.version.major) != 0
151 and int(paddle.version.major) <= 2
152 and int(paddle.version.minor) <= 4
153 ):
154 if not paddle.device.is_compiled_with_npu():
155 print(err.format("use_npu", "npu", "npu", "use_npu"))
156 sys.exit(1)
157 # is_compiled_with_npu() has been updated after paddle-2.4
158 else:
159 if not paddle.device.is_compiled_with_custom_device("npu"):
160 print(err.format("use_npu", "npu", "npu", "use_npu"))
161 sys.exit(1)
162 if use_mlu and not paddle.device.is_compiled_with_mlu():
163 print(err.format("use_mlu", "mlu", "mlu", "use_mlu"))
164 sys.exit(1)
165 if use_gcu and not paddle.device.is_compiled_with_custom_device("gcu"):
166 print(err.format("use_gcu", "gcu", "gcu", "use_gcu"))
167 sys.exit(1)
168 if use_metax_gpu and not paddle.device.is_compiled_with_custom_device(
169 "metax_gpu"
170 ):
171 print(
172 err.format("use_metax_gpu", "metax_gpu", "metax_gpu", "use_metax_gpu")
173 )
174 sys.exit(1)
175

Callers 1

preprocessFunction · 0.85

Calls 1

formatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…