Skip to content

Commit 1185849

Browse files
author
Sergey Shlyapnikov
authored
[GPU] Allow setting primitive's dependencies using index (#30436)
### Details: - This patch is preliminary work for updating the unfusion logic. It adds an additional method `primitive::get_dependency(size_t idx)`, which returns a mutable reference to the input_info associated with the specified dependency index, allowing to reconfigure it
1 parent bc5ad36 commit 1185849

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+432
-334
lines changed

src/plugins/intel_gpu/include/intel_gpu/primitives/activation.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ struct activation : public primitive_base<activation> {
120120
/// @brief PRelu activation slope input primitive id.
121121
/// Input x dimension should be equal to input feature size (one slope per channel).
122122
/// All other dimensions should be 1.
123-
primitive_id additional_params_input;
123+
input_info additional_params_input;
124124

125125
size_t hash() const override {
126126
size_t seed = primitive::hash();
127127
seed = hash_combine(seed, activation_function);
128128
seed = hash_combine(seed, additional_params.a);
129129
seed = hash_combine(seed, additional_params.b);
130-
seed = hash_combine(seed, additional_params_input.empty());
130+
seed = hash_combine(seed, additional_params_input.is_valid());
131131
return seed;
132132
}
133133

@@ -140,7 +140,7 @@ struct activation : public primitive_base<activation> {
140140
return activation_function == rhs_casted.activation_function &&
141141
additional_params.a == rhs_casted.additional_params.a &&
142142
additional_params.b == rhs_casted.additional_params.b &&
143-
additional_params_input.empty() == rhs_casted.additional_params_input.empty();
143+
additional_params_input.is_valid() == rhs_casted.additional_params_input.is_valid();
144144
}
145145

146146
void save(BinaryOutputBuffer& ob) const override {
@@ -158,10 +158,14 @@ struct activation : public primitive_base<activation> {
158158
}
159159

160160
protected:
161-
std::vector<input_info> get_dependencies() const override {
162-
if (additional_params_input.empty())
163-
return {};
164-
return {additional_params_input};
161+
std::map<size_t, const input_info*> get_dependencies_map() const override {
162+
auto ret = std::map<size_t, const input_info*>{};
163+
auto idx = input.size();
164+
165+
if (additional_params_input.is_valid())
166+
ret[idx++] = &additional_params_input;
167+
168+
return ret;
165169
}
166170
};
167171
} // namespace cldnn

src/plugins/intel_gpu/include/intel_gpu/primitives/adaptive_pooling.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ struct adaptive_pooling : public primitive_base<adaptive_pooling> {
7979

8080
adaptive_pooling_mode mode;
8181
tensor output_size;
82-
primitive_id indices_output;
82+
input_info indices_output;
8383
data_types index_element_type{data_types::i64};
8484

8585
size_t hash() const override {
8686
size_t seed = primitive::hash();
8787
seed = hash_combine(seed, mode);
8888
seed = hash_combine(seed, index_element_type);
89-
seed = hash_combine(seed, indices_output.empty());
89+
seed = hash_combine(seed, indices_output.is_valid());
9090
return seed;
9191
}
9292

@@ -118,10 +118,13 @@ struct adaptive_pooling : public primitive_base<adaptive_pooling> {
118118
}
119119

120120
protected:
121-
std::vector<input_info> get_dependencies() const override {
122-
std::vector<input_info> ret;
123-
if (!indices_output.empty())
124-
ret.push_back(indices_output);
121+
std::map<size_t, const input_info*> get_dependencies_map() const override {
122+
auto ret = std::map<size_t, const input_info*>{};
123+
auto idx = input.size();
124+
125+
if (indices_output.is_valid())
126+
ret[idx++] = &indices_output;
127+
125128
return ret;
126129
}
127130
};

src/plugins/intel_gpu/include/intel_gpu/primitives/condition.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ struct condition : public primitive_base<condition> {
111111
ib >> branch_true;
112112
ib >> branch_false;
113113
}
114-
115-
protected:
116-
std::vector<input_info> get_dependencies() const override { return {}; }
117114
};
118115

119116
static inline std::ostream& operator<< (std::ostream& os, condition::branch& info) {

src/plugins/intel_gpu/include/intel_gpu/primitives/convolution.hpp

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,15 @@ struct convolution : public primitive_base<convolution> {
187187
/// @param grouped_weights_shape Defines if weights tensor has explicit group dimension.
188188
bool grouped_weights_shape {false};
189189
/// @brief Primitive id containing weights data.
190-
const primitive_id weights;
190+
input_info weights;
191191
/// @brief Primitive id containing bias data.
192-
const primitive_id bias;
192+
input_info bias;
193193
/// @brief Primitive id containing weights zero points.
194-
const primitive_id weights_zero_points;
194+
input_info weights_zero_points;
195195
/// @brief Primitive id containing activations zero points.
196-
const primitive_id activations_zero_points;
196+
input_info activations_zero_points;
197197
/// @brief Primitive id containing compensation.
198-
const primitive_id compensation;
198+
input_info compensation;
199199

200200
size_t hash() const override {
201201
size_t seed = primitive::hash();
@@ -210,11 +210,11 @@ struct convolution : public primitive_base<convolution> {
210210
seed = hash_combine(seed, bilinear_interpolation_pad);
211211
seed = hash_combine(seed, transposed);
212212
seed = hash_combine(seed, grouped_weights_shape);
213-
seed = hash_combine(seed, !weights.empty());
214-
seed = hash_combine(seed, !bias.empty());
215-
seed = hash_combine(seed, !weights_zero_points.empty());
216-
seed = hash_combine(seed, !activations_zero_points.empty());
217-
seed = hash_combine(seed, !compensation.empty());
213+
seed = hash_combine(seed, !weights.is_valid());
214+
seed = hash_combine(seed, !bias.is_valid());
215+
seed = hash_combine(seed, !weights_zero_points.is_valid());
216+
seed = hash_combine(seed, !activations_zero_points.is_valid());
217+
seed = hash_combine(seed, !compensation.is_valid());
218218
return seed;
219219
}
220220

@@ -236,11 +236,11 @@ struct convolution : public primitive_base<convolution> {
236236
cmp_fields(bilinear_interpolation_pad) &&
237237
cmp_fields(transposed) &&
238238
cmp_fields(grouped_weights_shape) &&
239-
cmp_fields(weights.empty()) &&
240-
cmp_fields(bias.empty()) &&
241-
cmp_fields(weights_zero_points.empty()) &&
242-
cmp_fields(activations_zero_points.empty()) &&
243-
cmp_fields(compensation.empty());
239+
cmp_fields(weights.is_valid()) &&
240+
cmp_fields(bias.is_valid()) &&
241+
cmp_fields(weights_zero_points.is_valid()) &&
242+
cmp_fields(activations_zero_points.is_valid()) &&
243+
cmp_fields(compensation.is_valid());
244244
#undef cmp_fields
245245
}
246246

@@ -277,27 +277,32 @@ struct convolution : public primitive_base<convolution> {
277277
ib >> bilinear_interpolation_pad;
278278
ib >> transposed;
279279
ib >> grouped_weights_shape;
280-
ib >> *const_cast<primitive_id*>(&weights);
281-
ib >> *const_cast<primitive_id*>(&bias);
282-
ib >> *const_cast<primitive_id*>(&weights_zero_points);
283-
ib >> *const_cast<primitive_id*>(&activations_zero_points);
284-
ib >> *const_cast<primitive_id*>(&compensation);
280+
ib >> weights;
281+
ib >> bias;
282+
ib >> weights_zero_points;
283+
ib >> activations_zero_points;
284+
ib >> compensation;
285285
}
286286

287-
std::vector<input_info> get_dependencies() const override {
288-
std::vector<input_info> ret = {weights};
289-
if (!bias.empty()) {
290-
ret.push_back(bias);
291-
}
292-
if (!weights_zero_points.empty()) {
293-
ret.push_back(weights_zero_points);
294-
}
295-
if (!activations_zero_points.empty()) {
296-
ret.push_back(activations_zero_points);
297-
}
298-
if (!compensation.empty()) {
299-
ret.push_back(compensation);
300-
}
287+
protected:
288+
std::map<size_t, const input_info*> get_dependencies_map() const override {
289+
auto ret = std::map<size_t, const input_info*>{};
290+
auto idx = input.size();
291+
292+
OPENVINO_ASSERT(weights.is_valid());
293+
ret[idx++] = &weights;
294+
295+
if (bias.is_valid())
296+
ret[idx++] = &bias;
297+
298+
if (weights_zero_points.is_valid())
299+
ret[idx++] = &weights_zero_points;
300+
301+
if (activations_zero_points.is_valid())
302+
ret[idx++] = &activations_zero_points;
303+
304+
if (compensation.is_valid())
305+
ret[idx++] = &compensation;
301306

302307
return ret;
303308
}

src/plugins/intel_gpu/include/intel_gpu/primitives/deconvolution.hpp

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct deconvolution : public primitive_base<deconvolution> {
3131
/// @param activation_slp Relu activation slope.
3232
deconvolution(const primitive_id& id,
3333
const input_info& input,
34-
const std::vector<primitive_id>& weights,
35-
const std::vector<primitive_id>& bias,
34+
const primitive_id& weights,
35+
const primitive_id& bias,
3636
ov::Strides stride = {1, 1},
3737
ov::CoordinateDiff pad = {0, 0},
3838
ov::Strides dilations = {1, 1})
@@ -62,8 +62,8 @@ struct deconvolution : public primitive_base<deconvolution> {
6262
/// @param activation_slp Relu activation slope.
6363
deconvolution(const primitive_id& id,
6464
const input_info& input,
65-
const std::vector<primitive_id>& weights,
66-
const std::vector<primitive_id>& bias,
65+
const primitive_id& weights,
66+
const primitive_id& bias,
6767
uint32_t groups,
6868
ov::Strides stride = {1, 1},
6969
ov::CoordinateDiff pad = {0, 0},
@@ -93,7 +93,7 @@ struct deconvolution : public primitive_base<deconvolution> {
9393
/// @param activation_slp Relu activation slope.
9494
deconvolution(const primitive_id& id,
9595
const input_info& input,
96-
const std::vector<primitive_id>& weights,
96+
const primitive_id& weights,
9797
ov::Strides stride = {1, 1},
9898
ov::CoordinateDiff pad = {0, 0},
9999
ov::Strides dilations = {1, 1})
@@ -110,7 +110,7 @@ struct deconvolution : public primitive_base<deconvolution> {
110110
output_partial_shape({}),
111111
output_shape_id(""),
112112
weights(weights),
113-
bias(std::vector<primitive_id>(0)) {}
113+
bias("") {}
114114

115115
/// @brief Constructs deconvolution primitive (w/o bias).
116116
/// @param id This primitive id.
@@ -123,7 +123,7 @@ struct deconvolution : public primitive_base<deconvolution> {
123123
/// @param activation_slp Relu activation slope.
124124
deconvolution(const primitive_id& id,
125125
const input_info& input,
126-
const std::vector<primitive_id> &weights,
126+
const primitive_id& weights,
127127
uint32_t groups,
128128
ov::Strides stride = {1, 1},
129129
ov::CoordinateDiff pad = {0, 0},
@@ -141,7 +141,7 @@ struct deconvolution : public primitive_base<deconvolution> {
141141
output_partial_shape({}),
142142
output_shape_id(""),
143143
weights(weights),
144-
bias(std::vector<primitive_id>(0)) {}
144+
bias("") {}
145145

146146
/// @brief Constructs deconvolution primitive (computes input paddings to match output size).
147147
/// @param id This primitive id.
@@ -155,8 +155,8 @@ struct deconvolution : public primitive_base<deconvolution> {
155155
/// @param output_size User-defined output data size of the primitive (w/o padding).
156156
deconvolution(const primitive_id& id,
157157
const input_info& input,
158-
const std::vector<primitive_id>& weights,
159-
const std::vector<primitive_id>& bias,
158+
const primitive_id& weights,
159+
const primitive_id& bias,
160160
ov::Strides stride,
161161
ov::CoordinateDiff pad,
162162
ov::Strides dilations,
@@ -190,8 +190,8 @@ struct deconvolution : public primitive_base<deconvolution> {
190190
/// @param output_size User-defined output data size of the primitive (w/o padding).
191191
deconvolution(const primitive_id& id,
192192
const input_info& input,
193-
const std::vector<primitive_id>& weights,
194-
const std::vector<primitive_id>& bias,
193+
const primitive_id& weights,
194+
const primitive_id& bias,
195195
uint32_t groups,
196196
ov::Strides stride,
197197
ov::CoordinateDiff pad,
@@ -227,8 +227,8 @@ struct deconvolution : public primitive_base<deconvolution> {
227227
/// @param output_size User-defined output data size of the primitive (w/o padding).
228228
deconvolution(const primitive_id& id,
229229
const input_info& input,
230-
const std::vector<primitive_id>& weights,
231-
const std::vector<primitive_id>& bias,
230+
const primitive_id& weights,
231+
const primitive_id& bias,
232232
uint32_t groups,
233233
ov::Strides stride,
234234
ov::CoordinateDiff pad,
@@ -263,7 +263,7 @@ struct deconvolution : public primitive_base<deconvolution> {
263263
/// @param output_size User-defined output data size of the primitive (w/o padding).
264264
deconvolution(const primitive_id& id,
265265
const input_info& input,
266-
const std::vector<primitive_id>& weights,
266+
const primitive_id& weights,
267267
ov::Strides stride,
268268
ov::CoordinateDiff pad,
269269
ov::Strides dilations,
@@ -280,7 +280,7 @@ struct deconvolution : public primitive_base<deconvolution> {
280280
out_padding(pad.size(), 0),
281281
grouped_weights_shape(false),
282282
weights(weights),
283-
bias(std::vector<primitive_id>(0)) {}
283+
bias("") {}
284284

285285
/// @brief Constructs deconvolution primitive (computes input paddings to match output size).
286286
/// @param id This primitive id.
@@ -295,8 +295,8 @@ struct deconvolution : public primitive_base<deconvolution> {
295295
/// @return Deconvolution primitive with specified settings.
296296
static deconvolution create_with_output_size(const primitive_id& id,
297297
const input_info& input,
298-
const std::vector<primitive_id>& weights,
299-
const std::vector<primitive_id>& bias,
298+
const primitive_id& weights,
299+
const primitive_id& bias,
300300
tensor output_size,
301301
ov::Strides stride = {1, 1},
302302
ov::CoordinateDiff pad = {0, 0},
@@ -323,7 +323,7 @@ struct deconvolution : public primitive_base<deconvolution> {
323323
/// @return Deconvolution primitive with specified settings.
324324
static deconvolution create_with_output_size(const primitive_id& id,
325325
const input_info& input,
326-
const std::vector<primitive_id>& weights,
326+
const primitive_id& weights,
327327
tensor output_size,
328328
ov::Strides stride = {1, 1},
329329
ov::CoordinateDiff pad = {0, 0},
@@ -360,21 +360,21 @@ struct deconvolution : public primitive_base<deconvolution> {
360360
/// @brief Defines spatial shape of the output.
361361
ov::PartialShape output_partial_shape;
362362
/// @brief Data primitive id containing spatial shape of the output.
363-
primitive_id output_shape_id;
363+
input_info output_shape_id;
364364
/// @brief List of primitive ids containing weights data.
365-
const primitive_id_arr weights;
365+
input_info weights;
366366
/// @brief List of primitive ids containing bias data.
367-
const primitive_id_arr bias;
367+
input_info bias;
368368

369369
size_t hash() const override {
370370
size_t seed = primitive::hash();
371371
seed = hash_range(seed, pad.begin(), pad.end());
372372
seed = hash_range(seed, stride.begin(), stride.end());
373373
seed = hash_combine(seed, groups);
374374
seed = hash_combine(seed, grouped_weights_shape);
375-
seed = hash_combine(seed, weights.size());
376-
seed = hash_combine(seed, bias.size());
377-
seed = hash_combine(seed, output_shape_id.empty());
375+
seed = hash_combine(seed, weights.is_valid());
376+
seed = hash_combine(seed, bias.is_valid());
377+
seed = hash_combine(seed, output_shape_id.is_valid());
378378
return seed;
379379
}
380380

@@ -393,9 +393,9 @@ struct deconvolution : public primitive_base<deconvolution> {
393393
cmp_fields(pads_end) &&
394394
cmp_fields(out_padding) &&
395395
cmp_fields(grouped_weights_shape) &&
396-
cmp_fields(weights.size()) &&
397-
cmp_fields(bias.size()) &&
398-
cmp_fields(output_shape_id.empty());
396+
cmp_fields(weights.is_valid()) &&
397+
cmp_fields(bias.is_valid()) &&
398+
cmp_fields(output_shape_id.is_valid());
399399
#undef cmp_fields
400400
}
401401

@@ -431,17 +431,23 @@ struct deconvolution : public primitive_base<deconvolution> {
431431
ib >> grouped_weights_shape;
432432
ib >> output_partial_shape;
433433
ib >> output_shape_id;
434-
ib >> *const_cast<primitive_id_arr*>(&weights);
435-
ib >> *const_cast<primitive_id_arr*>(&bias);
434+
ib >> weights;
435+
ib >> bias;
436436
}
437437

438438
protected:
439-
std::vector<input_info> get_dependencies() const override {
440-
std::vector<input_info> ret;
441-
ret.reserve(weights.size() + bias.size() + (output_shape_id.empty() ? 0 : 1));
442-
for (auto& w : weights) ret.push_back(w);
443-
for (auto& b : bias) ret.push_back(b);
444-
if (!output_shape_id.empty()) ret.push_back(output_shape_id);
439+
std::map<size_t, const input_info*> get_dependencies_map() const override {
440+
auto ret = std::map<size_t, const input_info*>{};
441+
auto idx = input.size();
442+
443+
OPENVINO_ASSERT(weights.is_valid());
444+
ret[idx++] = &weights;
445+
446+
if (bias.is_valid())
447+
ret[idx++] = &bias;
448+
449+
if (output_shape_id.is_valid())
450+
ret[idx++] = &output_shape_id;
445451

446452
return ret;
447453
}

0 commit comments

Comments
 (0)