• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 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 #include "tensorflow/lite/delegates/hexagon/hexagon_nn/soc_model.h"
16 
17 #include <cstdlib>
18 
19 namespace tflite {
20 namespace delegates {
21 // Implementation below is similar to the one inside the Hexagon SDK for
22 // fetching the SoC information.
23 // TODO(b/144536839): Look in sharing the code with Hexagon SDK if possible.
24 
get_soc_id(int * soc_id)25 int get_soc_id(int* soc_id) {
26   int fd;
27   if (!access("/sys/devices/soc0/soc_id", F_OK)) {
28     fd = open("/sys/devices/soc0/soc_id", O_RDONLY);
29   } else {
30     fd = open("/sys/devices/system/soc/soc0/id", O_RDONLY);
31   }
32   if (fd == -1) {
33     return -1;
34   }
35 
36   char raw_buf[SOC_ID_BUFFER_LENGTH];
37   const int bytes_read = read(fd, raw_buf, SOC_ID_BUFFER_LENGTH - 1);
38   // read returns -1 on failure, so check and return if failed.
39   if (bytes_read == -1) {
40     return -1;  // failure
41   }
42   raw_buf[SOC_ID_BUFFER_LENGTH - 1] = 0;
43   *soc_id = atoi(raw_buf);
44   close(fd);
45 
46   return 0;
47 }
48 
getsoc_model()49 SocSkelTable getsoc_model() {
50   int soc_id;
51   get_soc_id(&soc_id);
52 
53   int i = 0;
54   for (i = 0; socSkelInfo[i].soc_id != 0; i++) {
55     if (socSkelInfo[i].soc_id == soc_id) {
56       return socSkelInfo[i];
57     }
58   }
59 
60   return socSkelInfo[i];
61 }
62 }  // namespace delegates
63 }  // namespace tflite
64