Skip to content

Commit ca724d5

Browse files
committed
Add bool type scalar
1 parent dff3f4d commit ca724d5

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

third_party/blink/renderer/modules/ml/neural_network_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class NeuralNetworkContext final : public ScriptWrappable,
3434
static const unsigned long kTensorFloat32 = 3;
3535
static const unsigned long kTensorInt32 = 4;
3636
static const unsigned long kTensorQuant8Asymm = 5;
37+
static const unsigned long kBool = 6;
3738
static const unsigned long kTensorQuant8SymmPerChannel = 11;
3839
static const unsigned long kTensorQuant8AsymmSigned = 14;
3940

third_party/blink/renderer/modules/ml/v2/nn_model.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ void NNModel::AddScalarOperand(uint32_t index, float value) {
169169
SetOperandValue(index, data.View());
170170
}
171171

172+
void NNModel::AddScalarOperand(uint32_t index, bool value) {
173+
model_info_->operands.push_back(ml::mojom::blink::Operand::New(
174+
static_cast<int32_t>(NeuralNetworkContext::kBool),
175+
WTF::Vector<uint32_t>(), 0, 0));
176+
177+
// setOperandValue
178+
int8_t convert = value ? 1 : 0;
179+
NotShared<DOMArrayBufferView> data =
180+
NotShared<DOMArrayBufferView>(DOMInt8Array::Create(&convert, 1));
181+
SetOperandValue(index, data.View());
182+
}
183+
172184
// Types prefaced with ANEURALNETWORKS_TENSOR_* must be used for tensor data
173185
// (i.e., tensors with at least one dimension).
174186
void NNModel::AddBiasOperand(uint32_t index, uint32_t output_channel) {

third_party/blink/renderer/modules/ml/v2/nn_model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class NNModel final : public ScriptWrappable {
3333
void BuildNeuralNetworkModel(Operand*);
3434
void AddScalarOperand(uint32_t index, int value);
3535
void AddScalarOperand(uint32_t index, float value);
36+
void AddScalarOperand(uint32_t index, bool value);
3637
void AddBiasOperand(uint32_t index, uint32_t output_channel);
3738
void AddTensorOperand(uint32_t index,
3839
Vector<uint32_t> dimensions,

third_party/blink/renderer/modules/ml/v2/ops/conv.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void Conv::AddLayer(NNModel* model, uint32_t& index) {
9696

9797
// Add layout operand and set the value.
9898
uint32_t layout_index = index++;
99-
model->AddScalarOperand(layout_index, layout_ == "nchw" ? 1 : 0);
99+
model->AddScalarOperand(layout_index, layout_ == "nchw" ? true : false);
100100
input_indexes.push_back(layout_index);
101101

102102
// Add conv output operand.

0 commit comments

Comments
 (0)