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

Function broadcastRequest

examples/cpp/bert/bert_triton_example.cc:28–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27template<typename T>
28std::vector<std::shared_ptr<std::unordered_map<std::string, triton::Tensor>>>
29broadcastRequest(const std::vector<T>& h_input_hidden_state,
30 const std::vector<int>& h_input_seq_len,
31 const size_t request_batch_size,
32 const size_t request_seq_len,
33 const size_t head_num,
34 const size_t size_per_head,
35 const int node_id,
36 const int gpu_count,
37 std::vector<void*>* pointer_record)
38{
39 std::vector<std::shared_ptr<std::unordered_map<std::string, triton::Tensor>>> request_list;
40 for (int device_id = 0; device_id < gpu_count; device_id++) {
41 ft::check_cuda_error(cudaSetDevice(device_id));
42
43 T* d_input_hidden_state;
44 int* d_input_seq_len;
45
46 ft::deviceMalloc(&d_input_hidden_state, h_input_hidden_state.size(), false);
47 ft::deviceMalloc(&d_input_seq_len, h_input_seq_len.size(), false);
48 ft::cudaH2Dcpy(d_input_hidden_state, h_input_hidden_state.data(), h_input_hidden_state.size());
49 ft::cudaH2Dcpy(d_input_seq_len, h_input_seq_len.data(), h_input_seq_len.size());
50
51 request_list.push_back(std::shared_ptr<std::unordered_map<std::string, triton::Tensor>>(
52 new std::unordered_map<std::string, triton::Tensor>(std::unordered_map<std::string, triton::Tensor>{
53 {"input_hidden_state",
54 triton::Tensor{triton::MEMORY_GPU,
55 std::is_same<T, float>::value ? triton::TYPE_FP32 : triton::TYPE_FP16,
56 std::vector<size_t>{request_batch_size, request_seq_len, head_num * size_per_head},
57 d_input_hidden_state}},
58 {"sequence_lengths",
59 triton::Tensor{triton::MEMORY_GPU,
60 triton::TYPE_INT32,
61 std::vector<size_t>{request_batch_size},
62 d_input_seq_len}}})));
63
64 pointer_record->push_back(d_input_hidden_state);
65 pointer_record->push_back(d_input_seq_len);
66 }
67
68 return request_list;
69}
70
71template<typename T>
72std::vector<std::shared_ptr<std::unordered_map<std::string, triton::Tensor>>>

Callers 1

prepareRequestFunction · 0.70

Calls 2

dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected