Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/device_network.h
| Context not available. | |||||
| #ifndef __DEVICE_NETWORK_H__ | #ifndef __DEVICE_NETWORK_H__ | ||||
| #define __DEVICE_NETWORK_H__ | #define __DEVICE_NETWORK_H__ | ||||
| #ifdef WITH_NETWORK | #if 1 || defined(WITH_NETWORK) | ||||
brecht: Why #if 1? | |||||
| #include <boost/archive/text_iarchive.hpp> | #include <boost/archive/text_iarchive.hpp> | ||||
| #include <boost/archive/text_oarchive.hpp> | #include <boost/archive/text_oarchive.hpp> | ||||
| Context not available. | |||||
| #include <boost/thread.hpp> | #include <boost/thread.hpp> | ||||
| #include <iostream> | #include <iostream> | ||||
| #include <sstream> | |||||
| #include <deque> | |||||
| #include "buffers.h" | #include "buffers.h" | ||||
| Context not available. | |||||
| #include "util_list.h" | #include "util_list.h" | ||||
| #include "util_map.h" | #include "util_map.h" | ||||
| #include "util_string.h" | #include "util_string.h" | ||||
| #include "util_debugtrace.h" | |||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| Context not available. | |||||
| RPCSend(tcp::socket& socket_, const string& name_ = "") | RPCSend(tcp::socket& socket_, const string& name_ = "") | ||||
| : name(name_), socket(socket_), archive(archive_stream), sent(false) | : name(name_), socket(socket_), archive(archive_stream), sent(false) | ||||
| { | { | ||||
| SyncOutputStream() << "Constructing RPC send: " << name; | |||||
| archive & name_; | archive & name_; | ||||
| } | } | ||||
| ~RPCSend() | ~RPCSend() | ||||
| { | { | ||||
| if(!sent) | if(!sent) | ||||
| fprintf(stderr, "Error: RPC %s not sent\n", name.c_str()); | SyncOutputStream() << "Error: RPC " << name << " not sent"; | ||||
| } | } | ||||
| void add(const device_memory& mem) | void add(const device_memory& mem) | ||||
| Context not available. | |||||
| archive & task.offset & task.stride; | archive & task.offset & task.stride; | ||||
| archive & task.shader_input & task.shader_output & task.shader_eval_type; | archive & task.shader_input & task.shader_output & task.shader_eval_type; | ||||
| archive & task.shader_x & task.shader_w; | archive & task.shader_x & task.shader_w; | ||||
| archive & task.need_finish_queue; | |||||
| } | } | ||||
| void add(const RenderTile& tile) | void add(const RenderTile& tile) | ||||
| { | { | ||||
| archive & tile.x & tile.y & tile.w & tile.h; | archive & tile.x & tile.y & tile.w & tile.h; | ||||
| archive & tile.start_sample & tile.num_samples & tile.sample; | archive & tile.start_sample & tile.num_samples & tile.sample; | ||||
| archive & tile.offset & tile.stride; | archive & tile.resolution & tile.offset & tile.stride; | ||||
| archive & tile.buffer & tile.rng_state; | archive & tile.buffer & tile.rng_state; | ||||
| } | } | ||||
| Context not available. | |||||
| header_stream << setw(8) << hex << archive_str.size(); | header_stream << setw(8) << hex << archive_str.size(); | ||||
| string header_str = header_stream.str(); | string header_str = header_stream.str(); | ||||
| SyncOutputStream() << "Sending output header, len=" << header_str.length(); | |||||
| boost::asio::write(socket, | boost::asio::write(socket, | ||||
| boost::asio::buffer(header_str), | boost::asio::buffer(header_str), | ||||
| boost::asio::transfer_all(), error); | boost::asio::transfer_all(), error); | ||||
| if(error.value()) | if(error.value()) | ||||
| cout << "Network send error: " << error.message() << "\n"; | SyncOutputStream() << "Network send error: " << error.message(); | ||||
| else | |||||
| SyncOutputStream() << "Sending output header done"; | |||||
| SyncOutputStream() << "Writing output data, len=" << archive_str.length(); | |||||
| /* then send actual data */ | /* then send actual data */ | ||||
| boost::asio::write(socket, | boost::asio::write(socket, | ||||
| Context not available. | |||||
| boost::asio::transfer_all(), error); | boost::asio::transfer_all(), error); | ||||
| if(error.value()) | if(error.value()) | ||||
| cout << "Network send error: " << error.message() << "\n"; | SyncOutputStream() << "Network send error: " << error.message(); | ||||
| else | |||||
| SyncOutputStream() << "Writing output data done" << archive_str.length(); | |||||
| sent = true; | sent = true; | ||||
| } | } | ||||
| void write_buffer(void *buffer, size_t size) | void write_buffer(void *buffer, size_t size) | ||||
| { | { | ||||
| SyncOutputStream() << "Writing BLOB, size=" << size; | |||||
| boost::system::error_code error; | boost::system::error_code error; | ||||
| boost::asio::write(socket, | boost::asio::write(socket, | ||||
| Context not available. | |||||
| boost::asio::transfer_all(), error); | boost::asio::transfer_all(), error); | ||||
| if(error.value()) | if(error.value()) | ||||
| cout << "Network send error: " << error.message() << "\n"; | SyncOutputStream() << "Network send error: " << error.message(); | ||||
| } | } | ||||
Not Done Inline ActionsI don't think this is portable, would not compile with visual studio. This also seems like temporary debugging code or is it really intended to be here? If it's not debugging code, it's not clear to me why we would raise SIGTRAP, would prefer to handle errors a bit more gracefully and at least print an error message. brecht: I don't think this is portable, would not compile with visual studio. This also seems like… | |||||
| protected: | protected: | ||||
| Context not available. | |||||
| RPCReceive(tcp::socket& socket_) | RPCReceive(tcp::socket& socket_) | ||||
| : socket(socket_), archive_stream(NULL), archive(NULL) | : socket(socket_), archive_stream(NULL), archive(NULL) | ||||
| { | { | ||||
| SyncOutputStream() << "Reading input header"; | |||||
| /* read head with fixed size */ | /* read head with fixed size */ | ||||
| vector<char> header(8); | vector<char> header(8); | ||||
| size_t len = boost::asio::read(socket, boost::asio::buffer(header)); | size_t len = boost::asio::read(socket, boost::asio::buffer(header)); | ||||
| static int race_detect; | |||||
| if (__sync_add_and_fetch(&race_detect, 1) != 1) { | |||||
| raise(SIGTRAP); | |||||
| } | |||||
| SyncOutputStream() << "Input header length=" << len; | |||||
| /* verify if we got something */ | /* verify if we got something */ | ||||
| if(len == header.size()) { | if(len == header.size()) { | ||||
| /* decode header */ | /* decode header */ | ||||
| Context not available. | |||||
| size_t data_size; | size_t data_size; | ||||
| if((header_stream >> hex >> data_size)) { | if((header_stream >> hex >> data_size)) { | ||||
| SyncOutputStream() << "Reading data, size=" << data_size; | |||||
| vector<char> data(data_size); | vector<char> data(data_size); | ||||
| size_t len = boost::asio::read(socket, boost::asio::buffer(data)); | size_t len = boost::asio::read(socket, boost::asio::buffer(data)); | ||||
| Context not available. | |||||
| archive = new boost::archive::text_iarchive(*archive_stream); | archive = new boost::archive::text_iarchive(*archive_stream); | ||||
| *archive & name; | *archive & name; | ||||
| SyncOutputStream() << "Got RPCReceive op: " << name; | |||||
| } | |||||
| else { | |||||
| SyncOutputStream() << "Network receive error: data size doesn't match header"; | |||||
| raise(SIGTRAP); | |||||
| } | } | ||||
| else | |||||
| cout << "Network receive error: data size doens't match header\n"; | |||||
| } | } | ||||
| else | else { | ||||
| cout << "Network receive error: can't decode data size from header\n"; | SyncOutputStream() << "Network receive error: can't decode data size from header"; | ||||
| raise(SIGTRAP); | |||||
| } | |||||
| } | |||||
| else { | |||||
| SyncOutputStream() << "Network receive error: invalid header size"; | |||||
| raise(SIGTRAP); | |||||
| } | |||||
| if (__sync_add_and_fetch(&race_detect, -1) != 0) { | |||||
| raise(SIGTRAP); | |||||
| } | } | ||||
| else | |||||
| cout << "Network receive error: invalid header size\n"; | |||||
| } | } | ||||
| ~RPCReceive() | ~RPCReceive() | ||||
| Context not available. | |||||
| size_t len = boost::asio::read(socket, boost::asio::buffer(buffer, size)); | size_t len = boost::asio::read(socket, boost::asio::buffer(buffer, size)); | ||||
| if(len != size) | if(len != size) | ||||
| cout << "Network receive error: buffer size doesn't match expected size\n"; | SyncOutputStream() << "Network receive error: buffer size doesn't match expected size"; | ||||
| } | } | ||||
| void read(DeviceTask& task) | void read(DeviceTask& task) | ||||
| Context not available. | |||||
| *archive & type & task.x & task.y & task.w & task.h; | *archive & type & task.x & task.y & task.w & task.h; | ||||
| *archive & task.rgba_byte & task.rgba_half & task.buffer & task.sample & task.num_samples; | *archive & task.rgba_byte & task.rgba_half & task.buffer & task.sample & task.num_samples; | ||||
| *archive & task.resolution & task.offset & task.stride; | *archive & task.offset & task.stride; | ||||
| *archive & task.shader_input & task.shader_output & task.shader_eval_type; | *archive & task.shader_input & task.shader_output & task.shader_eval_type; | ||||
| *archive & task.shader_x & task.shader_w; | *archive & task.shader_x & task.shader_w; | ||||
| *archive & task.need_finish_queue; | |||||
| task.type = (DeviceTask::Type)type; | task.type = (DeviceTask::Type)type; | ||||
| } | } | ||||
| Context not available. | |||||
| *archive & tile.x & tile.y & tile.w & tile.h; | *archive & tile.x & tile.y & tile.w & tile.h; | ||||
| *archive & tile.start_sample & tile.num_samples & tile.sample; | *archive & tile.start_sample & tile.num_samples & tile.sample; | ||||
| *archive & tile.resolution & tile.offset & tile.stride; | *archive & tile.resolution & tile.offset & tile.stride; | ||||
| *archive & tile.buffer & tile.rng_state & tile.rgba_byte & tile.rgba_half; | *archive & tile.buffer & tile.rng_state; | ||||
| tile.buffers = NULL; | tile.buffers = NULL; | ||||
| } | } | ||||
Not Done Inline ActionsIt's not clear to me why this line was changed, both would copy the vector the same way? brecht: It's not clear to me why this line was changed, both would copy the vector the same way? | |||||
Not Done Inline ActionsNot clear why error messages were removed. brecht: Not clear why error messages were removed. | |||||
| Context not available. | |||||
| delete work; | delete work; | ||||
| } | } | ||||
| list<string> get_server_list() | vector<string> get_server_list() | ||||
| { | { | ||||
| list<string> result; | vector<string> result; | ||||
| mutex.lock(); | mutex.lock(); | ||||
| result = servers; | result = vector<string>(servers.begin(), servers.end()); | ||||
| mutex.unlock(); | mutex.unlock(); | ||||
| return result; | return result; | ||||
| Context not available. | |||||
| void handle_receive_from(const boost::system::error_code& error, size_t size) | void handle_receive_from(const boost::system::error_code& error, size_t size) | ||||
| { | { | ||||
| if(error) { | if(error) { | ||||
| cout << "Server discovery receive error: " << error.message() << "\n"; | SyncOutputStream() << "Server discovery receive error: " << error.message(); | ||||
| return; | return; | ||||
| } | } | ||||
| Context not available. | |||||
| mutex.lock(); | mutex.lock(); | ||||
| /* add address if it's not already in the list */ | /* add address if it's not already in the list */ | ||||
| bool found = false; | bool found = std::find(servers.begin(), servers.end(), | ||||
| address) != servers.end(); | |||||
| foreach(string& server, servers) | |||||
| if(server == address) | |||||
| found = true; | |||||
| if(!found) | if(!found) | ||||
| servers.push_back(address); | servers.push_back(address); | ||||
Not Done Inline ActionsThis should be cycles_version, which may be a blender version for now but it's supposed to work standalone too. brecht: This should be cycles_version, which may be a blender version for now but it's supposed to work… | |||||
| Context not available. | |||||
| /* buffer and endpoint for receiving messages */ | /* buffer and endpoint for receiving messages */ | ||||
| char receive_buffer[256]; | char receive_buffer[256]; | ||||
| boost::asio::ip::udp::endpoint receive_endpoint; | boost::asio::ip::udp::endpoint receive_endpoint; | ||||
| // os, version, devices, status, host name, group name, ip as far as fields go | |||||
| struct ServerInfo { | |||||
| string blender_version; | |||||
| string os; | |||||
| int device_count; | |||||
| string status; | |||||
| string host_name; | |||||
| string group_name; | |||||
| string host_addr; | |||||
| }; | |||||
| /* collection of server addresses in list */ | /* collection of server addresses in list */ | ||||
| bool collect_servers; | bool collect_servers; | ||||
| list<string> servers; | vector<string> servers; | ||||
| }; | }; | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
| Context not available. | |||||
Why #if 1?