-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New FunctionTest #1132
New FunctionTest #1132
Conversation
hedaoyuan
commented
Jan 12, 2017
•
edited
Loading
edited
It is used to check the consistency between the BufferArg type argument received by Function and the original type argument.
…(do not contains data).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good to me. Approve it to make you move fast. Only minor comments need to be addressed.
std::make_shared<BufferArg>(cpuMemory_.back()->getBuf(), | ||
output.valueType(), | ||
output.shape(), | ||
ASSIGN_TO)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use argType here? pass from void addOutputs(const BufferArg& output, argType) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯,这里需要再考虑一下,目前有的Function实现上暂时只支持ADD_TO。我本来想的是是否所有Function都需要支持ASSIGN_TO。
std::make_shared<BufferArg>(gpuMemory_.back()->getBuf(), | ||
output.valueType(), | ||
output.shape(), | ||
ASSIGN_TO)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as line 82.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上。
|
||
// TODO: need be implemented. | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO, we may also need void addInputs(const SparseMatrixArg& input), I think I can do it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的。
|
||
void initArg(SequenceIdArg& arg, size_t batchSize) { | ||
size_t numSeqs = arg.numSeqs(); | ||
int* buf = (int*)arg.data(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use reinterpret_cast<int*>(arg.data())?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done。
autotest::TensorCheckErr(cpuVector, gpuVector); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO, do we need to compare the output of two sparse matrice or two sequences? If needed, we can do it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯,是需要的。
std::vector<BufferArgPtr>& outputs) { | ||
BufferArgs inArgs; | ||
BufferArgs outArgs; | ||
for (auto arg : inputs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto arg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上。
} | ||
|
||
void testBufferArgs(const BufferArgs& inputs, const CheckBufferArg& check) { | ||
check(inputs[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add CHECK_GE(inputs.size(), 1)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done。
argments.addArg(*matrix); | ||
std::vector<CheckBufferArg> checkFunc; | ||
checkFunc.push_back(check); | ||
testBufferArgs(argments, checkFunc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we only have one buffer arg and check function, can we directly write: check(argments)? Just curious :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testBufferArgs(argments, checkFunc);
这么写目的就是构造Function的调用过程;直接写成check(argments)的话相当于直接在TEST里面check。
|
||
~BufferArgs() { | ||
for (auto arg : _args_) { | ||
delete arg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, if args delete its arg, what will happen to the corresponding element in args_(std::vector<BufferArg*>)? Do we really need to worry about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里只是防止内存泄漏,~BufferArgs析构后,再使用BufferArgs::args_已经是非法了。
SequenceIdArg(const TensorShape& shape, ArgType argType = UNSPECIFIED) | ||
: BufferArg(VALUE_TYPE_INT32, shape, argType) { | ||
CHECK_EQ(shape_.ndims(), (size_t)1); | ||
numSeqs_ = shape_[0] - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to CHECK(shape_[0] > 1) or CHECK(shape_[0] >= 1) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done。
Add CHECK_GT(shape_[0], 1);