Skip to content
Open

11.22 #101

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/deep_dive/arch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ This document is intended for developers who want to understand the architecture
process logic for specific input data with strict mathematical
description, guiding the source code.

- The :ref:`operator-test` introduces the relevant content of
operator testing.

.. toctree::
:maxdepth: 2

system
infer_flow
math_formalization
operator_test
65 changes: 65 additions & 0 deletions docs/deep_dive/operator_test.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

.. _operator-test:

*************
Operator Test
*************

.. contents::

Test Method
-----------

First generate test data with test_ops.py, then verify the
generated data with test_op.cc, execute the following code
to test(test_op.cc is compiled with Makefile):

.. code-block::

python tests/test_ops.py
./test_op 0/1/2 (0 is cpu, 1 is formal, and 2 is gpu)

Test Results
------------

The following are the test results of the operator on different devices:

+-------------------+-------------------------+
| operator | results |
+===================+=========================+
| broadcast_sub | cpu & formal & gpu pass |
+-------------------+-------------------------+
| broadcast_add | cpu & formal & gpu pass |
+-------------------+-------------------------+
| broadcast_mul | cpu & formal & gpu pass |
+-------------------+-------------------------+
| broadcast_max | cpu & formal & gpu pass |
+-------------------+-------------------------+
| broadcast_div | cpu & formal & gpu pass |
+-------------------+-------------------------+
| broadcast_greater | cpu & formal & gpu pass |
+-------------------+-------------------------+
| max_pool2d | cpu & formal & gpu pass |
+-------------------+-------------------------+
| dense | cpu & formal & gpu pass |
+-------------------+-------------------------+
| sum | cpu & formal & gpu pass |
+-------------------+-------------------------+
| max | cpu & formal & gpu pass |
+-------------------+-------------------------+
| slice_like | cpu & formal & gpu pass |
+-------------------+-------------------------+
| tile | cpu & formal & gpu pass |
+-------------------+-------------------------+
| repeat | cpu & formal & gpu pass |
+-------------------+-------------------------+
| concatenate | cpu & formal & gpu pass |
+-------------------+-------------------------+
| transpose | cpu & formal & gpu pass |
+-------------------+-------------------------+
| take | cpu & formal & gpu pass |
+-------------------+-------------------------+
| get_valid_counts | cpu & formal & gpu pass |
+-------------------+-------------------------+
| strided_slice | cpu & formal & gpu pass |
+-------------------+-------------------------+
4 changes: 2 additions & 2 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ test_model_formal: test_model.cc
test_model_gpu: test_model.cc
g++ -o test_model_gpu test_model.cc -I../include -L../build/cpu/ -L../build/gpu/ -lcvm_runtime_cuda -lcudart -lcuda --std=c++11 -pthread -fopenmp -I./ -ldl -g -DUSE_GPU=1 -DCVM_PROFILING -fsigned-char

test_op:
g++ -o test_op test_op.cc -I../include -L../build/gpu -lcvm_runtime_cuda -lcuda -lcudart --std=c++11 -pthread -fopenmp -I../ -ldl -DCVM_PROFILING -fsigned-char -DUSE_GPU
test_op : test_op.cc
g++ -o test_op test_op.cc -I../include -L../build/ -lcvm_runtime --std=c++11 -pthread -fopenmp -I../ -ldl -g -fsigned-char

clean:
rm -f test_model_cpu test_model_formal test_model_gpu test_op
2 changes: 1 addition & 1 deletion tests/deprecated/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def verify_get_valid_counts():
def get_valid_counts(data, score_threshold):
np_data = np.array(data)
dshp = np_data.shape
if len(dshp) != 3 or (dshp[2] <= 2):
if len(dshp) != 3 or (dshp[2] < 2):
raise ValueError("data shape error: " + str(dshp))
batch_size, num_anchor, elem_length = dshp
np_out1 = np.zeros(shape=(batch_size,))
Expand Down
67 changes: 36 additions & 31 deletions tests/test_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ struct CVMOpParam {
std::string attrs;
};

#ifndef DEVICE
#define DEVICE 0
#endif
// #ifndef DEVICE
// #define DEVICE 1
// #endif

int ctx = APIDevTypeMap.at(DEVICE);
int ctx;

int device_id = 0;
/*
Expand Down Expand Up @@ -128,6 +128,9 @@ std::function<void()> get_func(
arg_ptr->arg_tcodes.push_back(kHandle);


// cvm.runtime.{version}.{op_name}
// cvm.runtime.cpu.conv2d
// cvm.runtime.cuda.dense
auto op = param.func_name;
int device_type = static_cast<int>(ctx);
std::string module_name = "cvm.runtime.";
Expand Down Expand Up @@ -472,7 +475,7 @@ void load_input(int num_inputs, string case_path, vector<vector<uint64_t>>& tsha
CVMArrayFree(cpu_tensor);
}
}
const string CASE_DIR = "/data/ops_generator";
const string CASE_DIR = "/home/remloveh/cvm-runtime/data/ops_generator";
//const string CASE_DIR = "/data/zkh";

void test_op(string op_name) {
Expand Down Expand Up @@ -659,36 +662,38 @@ void test_op(string op_name) {
// }
}
}
int main() {
test_op("max_pool2d"); // formal & cpu pass
test_op("upsampling"); // formal & cpu pass
test_op("dense"); // formal & cpu pass
int main(int argc, char* argv[]) {
ctx = APIDevTypeMap.at(stoi(argv[1]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more information about arguments, such as the meaning, format, etc.

// test_op("max_pool2d"); // formal & cpu pass
//test_op("upsampling"); // formal & cpu pass
// test_op("dense"); // formal & cpu pass
test_op("conv2d"); // formal & cpu pass
test_op("sum"); // formal & cpu pass
test_op("max"); // formal & cpu pass
test_op("slice_like"); // formal & cpu pass
test_op("tile"); // formal & cpu pass
test_op("repeat"); // formal & cpu pass
test_op("get_valid_counts"); // formal & CPU pass

test_op("strided_slice"); // formal & cpu pass
test_op("concatenate");// formal & cpu pass
test_op("transpose");// formal & cpu pass
test_op("take"); // formal & cpu pass
//test_op("clip"); // no test case
//test_op("cvm_clip"); // no test case
//test_op("cvm_right_shift"); // no test case
test_op("elemwise_add"); // formal & cpu pass
// test_op("sum"); // formal & cpu pass
// test_op("max"); // formal & cpu pass
// test_op("slice_like"); // formal & cpu pass
// test_op("tile"); // formal & cpu pass
// test_op("repeat"); // formal & cpu pass
// test_op("get_valid_counts"); // formal & CPU pass

// test_op("strided_slice"); // formal & cpu pass
// test_op("concatenate");// formal & cpu pass
// test_op("transpose");// formal & cpu pass
// test_op("take"); // formal & cpu pass
// test_op("clip"); // no test case
// test_op("cvm_clip"); // no test case
// test_op("cvm_right_shift"); // no test case
//test_op("elemwise_add"); // formal & cpu pass
//test_op("elemwise_sub"); // no test case
//test_op("where"); // no test case
test_op("non_max_suppression"); // formal & cpu pass
test_op("broadcast_sub"); // formal & cpu pass
test_op("broadcast_add"); // formal & cpu pass
test_op("broadcast_mul"); // formal & cpu pass
test_op("broadcast_max"); // formal & cpu pass
test_op("broadcast_div"); // formal & cpu pass
test_op("broadcast_greater"); // formal & cpu pass
//test_op("non_max_suppression"); // formal & cpu pass
// test_op("broadcast_sub"); // formal & cpu pass
// test_op("broadcast_add"); // formal & cpu pass
// test_op("broadcast_mul"); // formal & cpu pass
// test_op("broadcast_max"); // formal & cpu pass
// test_op("broadcast_div"); // formal & cpu pass
// test_op("broadcast_greater"); // formal & cpu pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the GPU pass information like your test documentation.


cout << "test device: "<< DeviceName(static_cast<int>(ctx)) << endl;
cout << "all tests finished" << endl;
return 0;
}