MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / allocateBuffer

Method allocateBuffer

src/fastertransformer/models/decoding/Decoding.cc:51–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50template<typename T>
51void Decoding<T>::allocateBuffer()
52{
53 FT_LOG_DEBUG(__PRETTY_FUNCTION__);
54 if (is_allocate_buffer_ == false) {
55 const size_t batchxbeam = max_batch_size_ * beam_width_;
56 const size_t self_cache_size = num_layer_ * batchxbeam * max_seq_len_ * hidden_units_;
57 const size_t mem_cache_size = num_layer_ * batchxbeam * mem_max_seq_len_ * hidden_units_;
58
59 if (vocab_size_ != vocab_size_padded_) {
60 padded_embedding_kernel_ = (T*)(allocator_->reMalloc(
61 padded_embedding_kernel_, sizeof(T) * hidden_units_ * vocab_size_padded_, true));
62 padded_embedding_bias_ =
63 (T*)(allocator_->reMalloc(padded_embedding_bias_, sizeof(T) * vocab_size_padded_, true));
64 padded_embedding_kernel_ptr_ = padded_embedding_kernel_;
65 padded_embedding_bias_ptr_ = padded_embedding_bias_;
66 }
67
68 decoder_input_buf_ =
69 (T*)(allocator_->reMalloc(decoder_input_buf_, sizeof(T) * batchxbeam * hidden_units_, false));
70 decoder_output_buf_ =
71 (T*)(allocator_->reMalloc(decoder_output_buf_, sizeof(T) * batchxbeam * hidden_units_, false));
72 normed_decoder_output_buf_ =
73 (T*)(allocator_->reMalloc(normed_decoder_output_buf_, sizeof(T) * batchxbeam * hidden_units_, false));
74 logits_buf_ = (DynamicDecodeType*)(allocator_->reMalloc(
75 logits_buf_, sizeof(DynamicDecodeType) * batchxbeam * vocab_size_padded_, false));
76 cum_log_probs_ = (float*)(allocator_->reMalloc(cum_log_probs_, sizeof(float) * batchxbeam, false));
77 finished_buf_ = (bool*)(allocator_->reMalloc(finished_buf_, sizeof(bool) * batchxbeam, false));
78 h_finished_buf_ = new bool[batchxbeam];
79
80 start_ids_buf_ = (int*)(allocator_->reMalloc(start_ids_buf_, sizeof(int) * max_batch_size_, false));
81 end_ids_buf_ = (int*)(allocator_->reMalloc(end_ids_buf_, sizeof(int) * max_batch_size_, false));
82
83 key_cache_ = (T*)(allocator_->reMalloc(key_cache_, sizeof(T) * self_cache_size, false));
84 value_cache_ = (T*)(allocator_->reMalloc(value_cache_, sizeof(T) * self_cache_size, false));
85 if (beam_width_ > 1) {
86 cache_indirections_[0] =
87 (int*)(allocator_->reMalloc(cache_indirections_, sizeof(int) * batchxbeam * max_seq_len_ * 2, true));
88 cache_indirections_[1] = cache_indirections_[0] + batchxbeam * max_seq_len_;
89 }
90 key_mem_cache_ = (T*)(allocator_->reMalloc(key_mem_cache_, sizeof(T) * mem_cache_size, false));
91 value_mem_cache_ = (T*)(allocator_->reMalloc(value_mem_cache_, sizeof(T) * mem_cache_size, false));
92
93 padded_pos_embedding_bias_ =
94 (T*)(allocator_->reMalloc(padded_pos_embedding_bias_, sizeof(T) * vocab_size_padded_, false));
95 output_ids_buf_ = (int*)(allocator_->reMalloc(output_ids_buf_, sizeof(int) * batchxbeam * max_seq_len_, false));
96 parent_ids_buf_ = (int*)(allocator_->reMalloc(parent_ids_buf_, sizeof(int) * batchxbeam * max_seq_len_, false));
97
98 is_allocate_buffer_ = true;
99 }
100}
101
102template<typename T>
103void Decoding<T>::freeBuffer()

Callers

nothing calls this directly

Calls 1

reMallocMethod · 0.80

Tested by

no test coverage detected