Commit 1f5627f9 by huchi

refactor XList: now a list has the same basic function as a STL vector

parent 72c9551b
......@@ -53,6 +53,9 @@ void TestDataManager() {
s[9] = 0;
str.Add(s);
cout << str.Get(0);
vector<int> x;
}
int main()
......
......@@ -51,10 +51,10 @@ void _MatrixMul2DMultiTheading(XList * args)
XTensor * c = matrixArgs->GetItem(2);
DTYPE alpha = *(DTYPE*)(matrixArgs->GetItem(3));
DTYPE beta = *(DTYPE*)(matrixArgs->GetItem(4));
int x1 = *(indexArgs->GetItem(0));
int y1 = *(indexArgs->GetItem(1));
int x2 = *(indexArgs->GetItem(2));
int y2 = *(indexArgs->GetItem(3));
int x1 = indexArgs->GetItem(0);
int y1 = indexArgs->GetItem(1);
int x2 = indexArgs->GetItem(2);
int y2 = indexArgs->GetItem(3);
#ifdef FAST_MATRIX
int am = a->dimSize[1];
......
......@@ -217,15 +217,15 @@ void _Merge(const XList * smalls, XTensor * big, int whereToMerge)
bool uniform = true;
int mergeNum = smalls->count;
XTensor* smallsItem0 = (XTensor*)(smalls->GetItem(0));
XTensor* smallsItem0 = smalls->GetItem(0);
int itemSize = smallsItem0->unitNum * smallsItem0->unitSize;
for (int i = 0; i < smalls->count; i++) {
XTensor* smallsItem = (XTensor*)smalls->GetItem(i);
XTensor* smallsItem = smalls->GetItem(i);
CheckNTErrors((big->unitNum == smallsItem->unitNum * mergeNum), "Unmatched tensors!");
if (i > 0) {
XTensor * preItem = (XTensor*)smalls->GetItem(i - 1);
XTensor * preItem = smalls->GetItem(i - 1);
if (smallsItem->unitNum * smallsItem->unitSize != (char*)smallsItem->data - (char*)preItem->data)
uniform = false;
}
......@@ -237,7 +237,7 @@ void _Merge(const XList * smalls, XTensor * big, int whereToMerge)
int gridNum = 1;
int mergedNum = smalls->count;
XTensor * s0 = (XTensor*)smalls->GetItem(0);
XTensor * s0 = smalls->GetItem(0);
int whereToMergeRDI = s0->order - whereToMerge - 1;
for (int i = 0; i < s0->order; i++) {
if (i <= whereToMergeRDI)
......@@ -263,7 +263,7 @@ void _Merge(const XList * smalls, XTensor * big, int whereToMerge)
for (int g = 0; g < gridNum; g++) {
char * tData = (char*)big->data + g * blockSize * blockNum * big->unitSize;
for (int k = 0; k < mergedNum; k++) {
XTensor * s = (XTensor*)smalls->GetItem(k);
XTensor * s = smalls->GetItem(k);
char * sData = (char*)s->data + g * blockSize * blockNum * s->unitSize;
XMemCopy2D(tData + k * tStep, tPtich, big->devID,
sData + k * sStep, sPitch, s->devID,
......@@ -295,7 +295,7 @@ void _Merge(const XList * smalls, XTensor * big, int whereToMerge)
/* copy from source to tmp */
if (!uniform) {
for (int i = 0; i < mergeNum; i++) {
XTensor* smallsItem = (XTensor*)smalls->GetItem(i);
XTensor* smallsItem = smalls->GetItem(i);
XMemCopy((char*)(tensorTMP->data) + (itemSize * i), tensorTMP->devID, smallsItem->data, smallsItem->devID, itemSize);
}
}
......@@ -324,7 +324,7 @@ make a new tensor to keep the result and return it
*/
XTensor Merge(const XList &smalls, int whereToMerge)
{
XTensor * tensor = (XTensor*)smalls.GetItem(0);
XTensor * tensor = smalls.GetItem(0);
int order = tensor->order;
int * dimSize = new int[order];
for (int i = 0; i < tensor->order; i++) {
......
......@@ -81,10 +81,10 @@ void RunParallel2D(XPRunner * parallelRunner, void * job,
XList * blockArgs = new XList(argNum);
int * blockIndex = indexList + i * 4;
indexArgs->Add(blockIndex);
indexArgs->Add(blockIndex + 1);
indexArgs->Add(blockIndex + 2);
indexArgs->Add(blockIndex + 3);
indexArgs->Add(blockIndex[0]);
indexArgs->Add(blockIndex[1]);
indexArgs->Add(blockIndex[2]);
indexArgs->Add(blockIndex[3]);
for (int j = 0; j < argNum; j++)
blockArgs->Add(jobArgList->GetItem(j));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论