This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C++] fix type inconsistent issue when loading quantized parameters (#…
…15038) * fix type inconsistent when using C++ API to load params file * add test case * fix cpplint * address comment * retrigger CI * fix comments * modify ci_test * fix indentation
- Loading branch information
1 parent
5763ba9
commit 93fdcad
Showing
4 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
#include <vector> | ||
#include "mxnet/c_api.h" | ||
#include "dmlc/logging.h" | ||
#include "mxnet-cpp/MxNetCpp.h" | ||
using namespace mxnet::cpp; | ||
|
||
enum TypeFlag { | ||
kFloat32 = 0, | ||
kFloat64 = 1, | ||
kFloat16 = 2, | ||
kUint8 = 3, | ||
kInt32 = 4, | ||
kInt8 = 5, | ||
kInt64 = 6, | ||
}; | ||
|
||
/* | ||
* The file is used for testing if there exist type inconsistency | ||
* when using Copy API to create a new NDArray. | ||
* By running: build/test_ndarray. | ||
*/ | ||
int main(int argc, char** argv) { | ||
std::vector<mx_uint> shape1{128, 2, 32}; | ||
Shape shape2(32, 8, 64); | ||
|
||
int gpu_count = 0; | ||
if (MXGetGPUCount(&gpu_count) != 0) { | ||
LOG(ERROR) << "MXGetGPUCount failed"; | ||
return -1; | ||
} | ||
|
||
Context context = (gpu_count > 0) ? Context::gpu() : Context::cpu(); | ||
|
||
NDArray src1(shape1, context, true, kFloat16); | ||
NDArray src2(shape2, context, false, kInt8); | ||
NDArray dst1, dst2; | ||
dst1 = src1.Copy(context); | ||
dst2 = src2.Copy(context); | ||
NDArray::WaitAll(); | ||
CHECK_EQ(src1.GetDType(), dst1.GetDType()); | ||
CHECK_EQ(src2.GetDType(), dst2.GetDType()); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters