Blender  V2.93
cycles_server.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <stdio.h>
18 
19 #include "device/device.h"
20 
21 #include "util/util_args.h"
22 #include "util/util_foreach.h"
23 #include "util/util_logging.h"
24 #include "util/util_path.h"
25 #include "util/util_stats.h"
26 #include "util/util_string.h"
27 #include "util/util_task.h"
28 
29 using namespace ccl;
30 
31 int main(int argc, const char **argv)
32 {
33  util_logging_init(argv[0]);
34  path_init();
35 
36  /* device types */
37  string devicelist = "";
38  string devicename = "cpu";
39  bool list = false, debug = false;
40  int threads = 0, verbosity = 1;
41 
42  vector<DeviceType> &types = Device::available_types();
43 
44  foreach (DeviceType type, types) {
45  if (devicelist != "")
46  devicelist += ", ";
47 
48  devicelist += Device::string_from_type(type);
49  }
50 
51  /* parse options */
52  ArgParse ap;
53 
54  ap.options("Usage: cycles_server [options]",
55  "--device %s",
56  &devicename,
57  ("Devices to use: " + devicelist).c_str(),
58  "--list-devices",
59  &list,
60  "List information about all available devices",
61  "--threads %d",
62  &threads,
63  "Number of threads to use for CPU device",
64 #ifdef WITH_CYCLES_LOGGING
65  "--debug",
66  &debug,
67  "Enable debug logging",
68  "--verbose %d",
69  &verbosity,
70  "Set verbosity of the logger",
71 #endif
72  NULL);
73 
74  if (ap.parse(argc, argv) < 0) {
75  fprintf(stderr, "%s\n", ap.geterror().c_str());
76  ap.usage();
77  exit(EXIT_FAILURE);
78  }
79 
80  if (debug) {
82  util_logging_verbosity_set(verbosity);
83  }
84 
85  if (list) {
87 
88  printf("Devices:\n");
89 
90  foreach (DeviceInfo &info, devices) {
91  printf(" %s%s\n", info.description.c_str(), (info.display_device) ? " (display)" : "");
92  }
93 
94  exit(EXIT_SUCCESS);
95  }
96 
97  /* find matching device */
98  DeviceType device_type = Device::type_from_string(devicename.c_str());
100  DeviceInfo device_info;
101 
102  foreach (DeviceInfo &device, devices) {
103  if (device_type == device.type) {
104  device_info = device;
105  break;
106  }
107  }
108 
110 
111  while (1) {
112  Stats stats;
113  Device *device = Device::create(device_info, stats, true);
114  printf("Cycles Server with device: %s\n", device->info.description.c_str());
115  device->server_run();
116  delete device;
117  }
118 
120 
121  return 0;
122 }
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
bool display_device
Definition: device.h:78
DeviceType type
Definition: device.h:74
string description
Definition: device.h:75
Definition: device.h:293
static Device * create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background=true)
Definition: device.cpp:382
static vector< DeviceInfo > available_devices(uint device_type_mask=DEVICE_MASK_ALL)
Definition: device.cpp:488
static DeviceType type_from_string(const char *name)
Definition: device.cpp:433
DeviceInfo info
Definition: device.h:337
static vector< DeviceType > available_types()
Definition: device.cpp:469
static string string_from_type(DeviceType type)
Definition: device.cpp:451
static void exit()
Definition: util_task.cpp:96
static void init(int num_threads=0)
Definition: util_task.cpp:75
int main(int argc, const char **argv)
DeviceType
Definition: device.h:43
static char ** types
Definition: makesdna.c:164
Vector< CPUDevice > devices
list of all CPUDevices. for every hardware thread an instance of CPUDevice is created
ListBase threads
list of all thread for every CPUDevice in cpudevices a thread exists.
void util_logging_init(const char *argv0)
void util_logging_verbosity_set(int verbosity)
void util_logging_start()
void path_init(const string &path, const string &user_path)
Definition: util_path.cpp:338