Add cuda inference example: #155 - #210
Conversation
| network.data_.inference_internal_projection_.end()) | ||
| network.network_.add_projection(std::move(projection)); | ||
| } | ||
| replace_wta_with_projections(network); |
There was a problem hiding this comment.
Должно заменять WTA на проекцию, но чот я не пойму, что там происходит внутри...
There was a problem hiding this comment.
Вот и я про тоже: какая-то непонятная фиговина, надо разобраться.
| if (!model_desc.model_saving_path_.empty()) | ||
| { | ||
| if (!model_desc.inference_only_) | ||
| { | ||
| save_network(model_desc, network); | ||
| } | ||
| knp::framework::Network new_network = knp::framework::sonata::load_network(model_desc.model_saving_path_); | ||
| if (new_network.populations_count() != network.network_.populations_count() | ||
| || new_network.projections_count() != network.network_.projections_count()) | ||
| { | ||
| std::cout << "Populations " << new_network.populations_count() << " vs. " | ||
| << network.network_.populations_count() << std::endl; | ||
| std::cout << "Projections: " << new_network.projections_count() << " vs. " | ||
| << network.network_.projections_count() << std::endl; | ||
| } | ||
| network.network_ = new_network; | ||
| } |
There was a problem hiding this comment.
Сохранение и загрузка обученной модели?
| */ | ||
| std::filesystem::path model_saving_path_; | ||
|
|
||
| /// A flag to not do the training. |
| }; | ||
|
|
||
|
|
||
| struct ValueIndex |
| gather_index_neuron_kernel<<<num_blocks, num_threads>>>(index.view(), inputs, buffer); | ||
| // in-place prefix sum, for each neuron the value is the number of synapses before this, starts with 0. | ||
| thrust::exclusive_scan(thrust::device, buffer, buffer + inputs.size_, buffer); | ||
| return CUDAVector<unsigned long long>{buffer, inputs.size_}; // The vector would take care of releasing |
|
|
||
|
|
||
| template <typename BaseSynapseType> | ||
| void Network::upcast_projections() |
There was a problem hiding this comment.
Думаю, что в Network этого быть не должно.
There was a problem hiding this comment.
А где должны быть функции, которые изменяют большой кусок Network?
There was a problem hiding this comment.
Функции должны быть во фреймворке (см., там уже есть то, что работает с Network), а вот методов таких не должно быть.
| is_converted = true; | ||
| return core::AllProjectionsVariant{res}; | ||
| } | ||
| return core::AllProjectionsVariant{proj}; // TODO: Remove unnecessary copying. |
| network.data_.inference_internal_projection_.end()) | ||
| network.network_.add_projection(std::move(projection)); | ||
| } | ||
| replace_wta_with_projections(network); |
There was a problem hiding this comment.
Вот и я про тоже: какая-то непонятная фиговина, надо разобраться.
| // /** | ||
| // * @brief Send a message to the message bus. | ||
| // * @param message message to send. | ||
| // */ | ||
| // template <class MessageType> | ||
| // __host__ __device__ void send_message(const MessageType &message); |
| for (auto iter = buffer.begin(); iter != buffer.end(); ++iter) | ||
| { | ||
| LongIndex current_neuron = (*iter).first; | ||
| // Filling offsets for skipped neurons: if first three are missing that would be (0, 0, 0, 0, 5... |
There was a problem hiding this comment.
Скобку в комменте не закрыл.
| template <class T> | ||
| struct CUDAVectorView | ||
| { | ||
| const T * const data_; | ||
| const unsigned long long size_; | ||
| }; | ||
|
|
||
| template <class T> | ||
| struct CUDAVectorMutableView | ||
| { | ||
| T * const data_; | ||
| const unsigned long long size_; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Потому что есть отдельно векторы, отдельно view, и если сюда будет что-то ещё добавляться, тут будет помойка.
| { | ||
| #if defined(__CUDA_ARCH__) | ||
| PRINTF_TRACE("Using has_sender on device\n"); | ||
| // PRINTF_TRACE("Using has_sender on device\n"); |
There was a problem hiding this comment.
FAST_ERROR_CHECK же, вроде, был?
| size_t tail_length = end() - end_iter; | ||
| size_t num_destruct = end() - begin_iter; | ||
| #ifdef __CUDA_ARCH__ | ||
| #ifdef __CUDA_ARCH__ // Device only |
There was a problem hiding this comment.
- Вообще-то, у нас есть style guide, и никаких "вопросов читабельности" не должно возникать.
- Это и нужно для того, чтобы разбивать функцию и видеть макрос, - лишняя "красота" здесь только мешает.
| // size_t new_heap = 128 * 1024 * 1024; // 128 Mb // TEMP! | ||
| // cudaDeviceSetLimit(cudaLimitMallocHeapSize, new_heap); |
| @@ -176,23 +176,23 @@ public: | |||
| * @brief Get an iterator pointing to the first element of the population loaded to backend. | |||
| * @return population iterator. | |||
| */ | |||
| __host__ __device__ PopulationIterator begin_populations(); | |||
| __host__ PopulationIterator begin_populations(); | |||
There was a problem hiding this comment.
А если я хочу итерироваться на устройстве по ним?
|
|
||
|
|
||
| template <typename BaseSynapseType> | ||
| void Network::upcast_projections() |
There was a problem hiding this comment.
Функции должны быть во фреймворке (см., там уже есть то, что работает с Network), а вот методов таких не должно быть.
Adding CUDA inference example. Now CUDA backend works at least with a decent speed.