Skip to content

Commit

Permalink
sync with dawn
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa0314 committed May 30, 2022
1 parent ff55f0b commit fbd91af
Show file tree
Hide file tree
Showing 37 changed files with 422 additions and 143 deletions.
13 changes: 10 additions & 3 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ gclient_gn_args = [

vars = {
'chromium_git': 'https://chromium.googlesource.com',
'dawn_git': 'https://github.com/fujunwei',
# 'dawn_git': 'https://github.com/fujunwei',
'dawn_git': 'https://github.com/lisa0314',
'github_git': 'https://github.com',

'dawn_standalone': True,
Expand Down Expand Up @@ -45,9 +46,15 @@ deps = {

# Dependencies required for code generator and infrastructure code.
'third_party/dawn': {
'url': '{dawn_git}/dawn.git@f4c84e239bf8b5b2c4733d68ca38e1e9049fd895'
# 'url': '{dawn_git}/dawn.git@f4c84e239bf8b5b2c4733d68ca38e1e9049fd895'
'url': '{dawn_git}/dawn.git@5e6f6fbfcb038e7a0f7857cda186a8771c6eba05'
},

'third_party/abseil-cpp': {
'url': '{chromium_git}/chromium/src/third_party/abseil-cpp@789af048b388657987c59d4da406859034fe310f',
'condition': 'dawn_standalone',
},

# Dependencies required for backends.
'third_party/DirectML': {
'url': '{github_git}/microsoft/DirectML.git@c3f16a701beeeefc9ce5b67c71b554a6903c0f67',
Expand Down Expand Up @@ -136,7 +143,7 @@ deps = {

# Jinja2 and MarkupSafe for the code generator
'third_party/jinja2': {
'url': '{chromium_git}/chromium/src/third_party/jinja2@a82a4944a7f2496639f34a89c9923be5908b80aa',
'url': '{chromium_git}/chromium/src/third_party/jinja2@ee69aa00ee8536f61db6a451f3858745cf587de6',
'condition': 'dawn_standalone',
},
'third_party/markupsafe': {
Expand Down
5 changes: 3 additions & 2 deletions examples/MobileNetV2/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ int main(int argc, const char* argv[]) {
}
},
&mobilevetv2);

wnn::GraphBuilder builder = utils::CreateGraphBuilder(context);
wnn::Operand output = mobilevetv2.mLayout == "nchw" ? mobilevetv2.LoadNCHW(builder)
: mobilevetv2.LoadNHWC(builder);
wnn::Operand output = mobilevetv2.mLayout == "nchw" ? mobilevetv2.LoadNchw(builder)
: mobilevetv2.LoadNhwc(builder);

// Build the graph.
const std::chrono::time_point<std::chrono::high_resolution_clock> compilationStartTime =
Expand Down
8 changes: 6 additions & 2 deletions examples/SampleUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ wnn::Context CreateCppContext(wnn::ContextOptions const* options) {
// Choose whether to use the backend procs and context directly, or set up the wire.
WNNContext context = nullptr;
WebnnProcTable procs;
WNNInstance wnnInstance;


switch (cmdBufType) {
case CmdBufType::None:
procs = backendProcs;
context = backendContext;
instance = wnn::Instance(nativeInstance->Get());
wnnInstance = nativeInstance->Get();
break;

case CmdBufType::Terrible: {
Expand Down Expand Up @@ -100,14 +102,16 @@ wnn::Context CreateCppContext(wnn::ContextOptions const* options) {
instanceReservation.generation);
// Keep the reference instread of using Acquire.
// TODO:: make the instance in the client as singleton object.
instance = wnn::Instance(instanceReservation.instance);
wnnInstance = instanceReservation.instance;
break;
#endif
}
default:
dawn::ErrorLog() << "Invaild CmdBufType";
DAWN_ASSERT(0);
}
webnnProcSetProcs(&procs);
instance = wnn::Instance(wnnInstance);
return instance.CreateContext(options);
;
}
Expand Down
2 changes: 2 additions & 0 deletions generator/webnn_generator.gni
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ template("webnn_generator") {
deps = [ "${dawn_root}/generator:remove_stale_autogen_files" ]

template_dir = "${dawn_root}/generator/templates"

}
}

Expand Down Expand Up @@ -121,5 +122,6 @@ template("webnn_json_generator") {
]

forward_variables_from(invoker, "*", [ "target" ])

}
}
2 changes: 2 additions & 0 deletions include/webnn/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ config("public") {
include_dirs = [
"${target_gen_dir}/../../include",
"${webnn_root}/include",
"${dawn_root}/include",
"${dawn_gen_root}/include",
]

if (build_with_chromium) {
Expand Down
6 changes: 5 additions & 1 deletion include/webnn/wire/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ namespace webnn::wire {

class WEBNN_WIRE_EXPORT CommandSerializer {
public:
virtual ~CommandSerializer() = default;
CommandSerializer();
virtual ~CommandSerializer();
CommandSerializer(const CommandSerializer& rhs) = delete;
CommandSerializer& operator=(const CommandSerializer& rhs) = delete;

// Get space for serializing commands.
// GetCmdSpace will never be called with a value larger than
Expand All @@ -35,6 +38,7 @@ namespace webnn::wire {
virtual void* GetCmdSpace(size_t size) = 0;
virtual bool Flush() = 0;
virtual size_t GetMaximumAllocationSize() const = 0;
virtual void OnSerializeError();
};

class WEBNN_WIRE_EXPORT CommandHandler {
Expand Down
9 changes: 9 additions & 0 deletions src/webnn/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ config("internal_config") {
"-Wshadow-field",
"-Wstrict-prototypes",
"-Wtautological-unsigned-zero-compare",
"-Wno-unused-function",
]

# Allow comparison against type limits that might be tautological on 32bit
Expand Down Expand Up @@ -184,6 +185,14 @@ config("internal_config") {
"-Wno-c++17-extensions",
]
}


if (is_clang && webnn_enable_wire) {
cflags += [
"-Wno-unused-function",
]
}

}

###############################################################################
Expand Down
6 changes: 3 additions & 3 deletions src/webnn/native/ops/Conv2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ namespace webnn::native::op {
if (options != nullptr && options->bias != nullptr) {
mInputs.push_back(options->bias);
}
if (options == nullptr || options->padding == nullptr) {
if (options == nullptr || options->paddingCount == 0) {
mPadding = std::vector<int32_t>(4, 0);
} else {
mPadding.assign(options->padding, options->padding + options->paddingCount);
}
mOptions.padding = mPadding.data();
mOptions.paddingCount = mPadding.size();

if (options == nullptr || options->strides == nullptr) {
if (options == nullptr || options->stridesCount == 0) {
mStride = std::vector<int32_t>(2, 1);
} else {
mStride.assign(options->strides, options->strides + options->stridesCount);
}
mOptions.strides = mStride.data();
mOptions.stridesCount = mStride.size();

if (options == nullptr || options->dilations == nullptr) {
if (options == nullptr || options->dilationsCount == 0) {
mDilations = std::vector<int32_t>(2, 1);
} else {
mDilations.assign(options->dilations, options->dilations + options->dilationsCount);
Expand Down
6 changes: 3 additions & 3 deletions src/webnn/native/ops/ConvTranspose2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace webnn::native::op {
OperandBase* filter,
ConvTranspose2dOptions const* options)
: Conv2dBase(builder, input, filter, options) {
if (options == nullptr || options->outputPadding == nullptr) {
if (options == nullptr || options->outputPaddingCount == 0) {
mOutputPadding = std::vector<int32_t>(2, 0);
} else {
mOutputPadding.assign(options->outputPadding,
Expand All @@ -34,7 +34,7 @@ namespace webnn::native::op {
mOptions.outputPadding = mOutputPadding.data();
mOptions.outputPaddingCount = mOutputPadding.size();

if (options != nullptr && options->outputSizes != nullptr) {
if (options != nullptr && options->outputSizesCount != 0) {
mOutputSizes.assign(options->outputSizes,
options->outputSizes + options->outputSizesCount);
mOptions.outputSizes = mOutputSizes.data();
Expand Down Expand Up @@ -113,7 +113,7 @@ namespace webnn::native::op {
}

int32_t outputHeight, outputWidth;
if (mOptions.outputSizes != nullptr) {
if (mOptions.outputSizesCount != 0) {
outputHeight = mOptions.outputSizes[0];
outputWidth = mOptions.outputSizes[1];
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/webnn/native/ops/Pool2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ namespace webnn::native::op {
OperandBase* input,
Pool2dOptions const* options)
: OperatorBase(builder, {input}), mOpType(opType) {
if (options != nullptr && options->windowDimensions != nullptr) {
if (options != nullptr && options->windowDimensionsCount != 0) {
mWindowDimensions.assign(options->windowDimensions,
options->windowDimensions + options->windowDimensionsCount);
mOptions.windowDimensions = mWindowDimensions.data();
mOptions.windowDimensionsCount = mWindowDimensions.size();
}

if (options == nullptr || options->padding == nullptr) {
if (options == nullptr || options->paddingCount == 0) {
mPadding = std::vector<int32_t>(4, 0);
} else {
mPadding.assign(options->padding, options->padding + options->paddingCount);
}
mOptions.padding = mPadding.data();
mOptions.paddingCount = mPadding.size();

if (options == nullptr || options->strides == nullptr) {
if (options == nullptr || options->stridesCount == 0) {
mStride = std::vector<int32_t>(2, 1);
} else {
mStride.assign(options->strides, options->strides + options->stridesCount);
}
mOptions.strides = mStride.data();
mOptions.stridesCount = mStride.size();

if (options == nullptr || options->dilations == nullptr) {
if (options == nullptr || options->dilationsCount == 0) {
mDilations = std::vector<int32_t>(2, 1);
} else {
mDilations.assign(options->dilations, options->dilations + options->dilationsCount);
Expand All @@ -62,7 +62,7 @@ namespace webnn::native::op {
mOptions.roundingType =
options == nullptr ? wnn::RoundingType::Floor : options->roundingType;

if (options != nullptr && options->outputSizes != nullptr) {
if (options != nullptr && options->outputSizesCount != 0) {
mOutputSizes.assign(options->outputSizes,
options->outputSizes + options->outputSizesCount);
mOptions.outputSizes = mOutputSizes.data();
Expand Down
2 changes: 1 addition & 1 deletion src/webnn/native/ops/Reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace webnn::native::op {
ReduceOptions const* options)
: OperatorBase(builder, {input}), mOpType(opType) {
// If axes are not present, all dimensions are reduced.
if (options == nullptr || options->axes == nullptr) {
if (options == nullptr || options->axesCount == 0) {
int32_t rank = input->Shape().size();
mAxes.resize(rank);
for (auto i = 0; i < rank; ++i) {
Expand Down
7 changes: 4 additions & 3 deletions src/webnn/native/ops/Resample2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "webnn/native/ops/Resample2d.h"
#include "common/Log.h"

#include <algorithm>

Expand All @@ -25,13 +26,13 @@ namespace webnn::native::op {
: OperatorBase(builder, {input}), mScales({1.0, 1.0}), mSizes({}), mAxes({2, 3}) {
mOptions.mode =
options == nullptr ? wnn::InterpolationMode::NearestNeighbor : options->mode;
if (options != nullptr && options->scales != nullptr) {
if (options != nullptr && options->scalesCount != 0) {
mScales.assign(options->scales, options->scales + options->scalesCount);
}
if (options != nullptr && options->sizes != nullptr) {
if (options != nullptr && options->sizesCount != 0) {
mSizes.assign(options->sizes, options->sizes + options->sizesCount);
}
if (options != nullptr && options->axes != nullptr) {
if (options != nullptr && options->axesCount != 0) {
mAxes.assign(options->axes, options->axes + options->axesCount);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/webnn/native/ops/Slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace webnn::native::op {
uint32_t sizesCount,
SliceOptions const* options)
: OperatorBase(builder, {input}) {
if (options != nullptr && options->axes != nullptr) {
if (options != nullptr && options->axesCount != 0) {
mAxes.assign(options->axes, options->axes + options->axesCount);
}

Expand Down
2 changes: 1 addition & 1 deletion src/webnn/native/ops/Transpose.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace webnn::native::op {
public:
Transpose(GraphBuilderBase* builder, OperandBase* input, TransposeOptions const* options)
: OperatorBase(builder, {input}) {
if (options == nullptr || options->permutation == nullptr) {
if (options == nullptr || options->permutationCount == 0) {
int32_t rank = input->Shape().size();
mPermutation.resize(rank);
for (auto i = 0; i < rank - 1; i++) {
Expand Down
Loading

0 comments on commit fbd91af

Please sign in to comment.