• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 package com.example.android.tflitecamerademo;
17 
18 import org.tensorflow.lite.Delegate;
19 
20 /**
21  * Helper class for {@code GpuDelegate}.
22  *
23  * <p>WARNING: This is an experimental API and subject to change.
24  */
25 public class GpuDelegateHelper {
GpuDelegateHelper()26   private GpuDelegateHelper() {}
27 
28   /** Checks whether {@code GpuDelegate} is available. */
isGpuDelegateAvailable()29   public static boolean isGpuDelegateAvailable() {
30     try {
31       Class.forName("org.tensorflow.lite.experimental.GpuDelegate");
32       return true;
33     } catch (Exception e) {
34       return false;
35     }
36   }
37 
38   /** Returns an instance of {@code GpuDelegate} if available. */
createGpuDelegate()39   public static Delegate createGpuDelegate() {
40     try {
41       return Class.forName("org.tensorflow.lite.experimental.GpuDelegate")
42           .asSubclass(Delegate.class)
43           .getDeclaredConstructor()
44           .newInstance();
45     } catch (Exception e) {
46       throw new IllegalStateException(e);
47     }
48   }
49 }
50