Conversation
samples/core/mulmatrix/main.cpp
Outdated
| struct Matrix | ||
| { | ||
| unsigned int mRows; | ||
| unsigned int mCols; | ||
| std::vector<int> mData; |
There was a problem hiding this comment.
Preference to use data independent structure which will accept basic OpenCL types as follows: cl_[u]short, cl_[u]int, cl_[u]long, cl_half, cl_float, cl_double
samples/core/mulmatrix/main.cpp
Outdated
| std::vector<int> data; | ||
| data.reserve(size); | ||
| for (unsigned int i = 0; i < size; ++i) | ||
| { | ||
| data.push_back(distr(generator)); | ||
| } | ||
| mData = std::move(data); |
There was a problem hiding this comment.
What is the point to introduce second vector and perform move operation ? I see this shouldn't be a performance hit but still additional code may confuse WG reviewers.
There was a problem hiding this comment.
@shajder This is corrected by introducing another constructor
samples/core/mulmatrix/main.cpp
Outdated
| Matrix& A; | ||
| Matrix& B; |
There was a problem hiding this comment.
Preference to use smart pointers
samples/core/mulmatrix/main.cpp
Outdated
| std::string name; | ||
| platform.getInfo(CL_PLATFORM_NAME, &name); | ||
| std::cout << "Platform: " << name << std::endl; | ||
|
|
||
| std::vector<cl::Device> platformDevices; |
There was a problem hiding this comment.
Could we move reusable variables outside the loop content ?
samples/core/mulmatrix/main.cpp
Outdated
| { | ||
| for (auto& context : mContexts) | ||
| { | ||
| mPrograms.emplace_back(cl::Program(context, mKernelSource, true)); |
There was a problem hiding this comment.
Preference to call cl::Program::build explicitly to log possible errors with cl::BuildError
samples/core/mulmatrix/main.cpp
Outdated
| cl::Buffer resultMatBuffer(mContexts[gpu], CL_MEM_WRITE_ONLY, | ||
| mMatDims.fstMtxRows * mMatDims.sndMtxCols * sizeof(int)); |
There was a problem hiding this comment.
Bug spotted around here, what is missing is initialization of result buffer with enqueueFillBuffer. This will eventually accumulate garbage from uninitialized buffer during operation of matrix merging.
There was a problem hiding this comment.
@shajder I have added enqueueFillBuffer
samples/core/mulmatrix/main.cpp
Outdated
| } | ||
|
|
||
|
|
||
| std::lock_guard<std::mutex> lk(m); |
There was a problem hiding this comment.
I didn't fully investigate that but I have an observation which makes me think this makes all the threads running in sync.
There was a problem hiding this comment.
@shajder I have tested it with sleeping one one thread and in console it is visible that one thread finishes and it it waiting for another.
samples/core/mulmatrix/main.cpp
Outdated
| std::transform(result.mData.begin(), result.mData.end(), helper.mData.begin(), | ||
| result.mData.begin(), std::plus<int>()); |
There was a problem hiding this comment.
accumulating garbabe data from unitialized result buffer above
There was a problem hiding this comment.
@shajder enqueueFillBuffer was added as you told in previous comment.
| bool MatrixMultiplication::LoadKernel() | ||
| { | ||
| //std::string fileName("C:\\RND200\\OpenCL-SDK\\samples\\core\\mulmatrix\\mulMatrix.cl"); | ||
| std::string fileName("mulMatrix.cl"); |
There was a problem hiding this comment.
This is minor but I think it is slightly more convenient to have such a small kernel source in the same source file
samples/core/mulmatrix/main.cpp
Outdated
| unsigned int rows1 = matDims.fstMtxRows; | ||
| unsigned int cols1 = matDims.fstMtxCols; | ||
| unsigned int rows2 = matDims.sndMtxRows; | ||
| unsigned int cols2 = matDims.sndMtxCols; |
There was a problem hiding this comment.
Preference for validation of maximum ranges to avoid vague errors as result
5161df4 to
7067f0c
Compare
9685cdd to
16716fd
Compare
16716fd to
00c74c9
Compare
No description provided.