Cuda use streams and async to avoid busywaiting
[blender.git] / intern / cycles / app / cycles_server.cpp
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.h"
20
21 #include "util_args.h"
22 #include "util_foreach.h"
23 #include "util_path.h"
24 #include "util_stats.h"
25 #include "util_string.h"
26 #include "util_task.h"
27
28 using namespace ccl;
29
30 int main(int argc, const char **argv)
31 {
32         path_init();
33
34         /* device types */
35         string devicelist = "";
36         string devicename = "cpu";
37         bool list = false;
38         int threads = 0;
39
40         vector<DeviceType>& types = Device::available_types();
41
42         foreach(DeviceType type, types) {
43                 if(devicelist != "")
44                         devicelist += ", ";
45
46                 devicelist += Device::string_from_type(type);
47         }
48
49         /* parse options */
50         ArgParse ap;
51
52         ap.options ("Usage: cycles_server [options]",
53                 "--device %s", &devicename, ("Devices to use: " + devicelist).c_str(),
54                 "--list-devices", &list, "List information about all available devices",
55                 "--threads %d", &threads, "Number of threads to use for CPU device",
56                 NULL);
57
58         if(ap.parse(argc, argv) < 0) {
59                 fprintf(stderr, "%s\n", ap.geterror().c_str());
60                 ap.usage();
61                 exit(EXIT_FAILURE);
62         }
63         else if(list) {
64                 vector<DeviceInfo>& devices = Device::available_devices();
65
66                 printf("Devices:\n");
67
68                 foreach(DeviceInfo& info, devices) {
69                         printf("    %s%s\n",
70                                 info.description.c_str(),
71                                 (info.display_device)? " (display)": "");
72                 }
73
74                 exit(EXIT_SUCCESS);
75         }
76
77         /* find matching device */
78         DeviceType device_type = Device::type_from_string(devicename.c_str());
79         vector<DeviceInfo>& devices = Device::available_devices();
80         DeviceInfo device_info;
81
82         foreach(DeviceInfo& device, devices) {
83                 if(device_type == device.type) {
84                         device_info = device;
85                         break;
86                 }
87         }
88
89         TaskScheduler::init(threads);
90
91         while(1) {
92                 Stats stats;
93                 Device *device = Device::create(device_info, stats, true);
94                 printf("Cycles Server with device: %s\n", device->info.description.c_str());
95                 device->server_run();
96                 delete device;
97         }
98
99         TaskScheduler::exit();
100
101         return 0;
102 }
103