cycles_server.cpp 3.0 KB

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