Commit bb5eb7db by liyinqiao

Bug fixed. (This version cannot run on the GPUs with pascal and much older framework).

1. Fix the memory leak bugs in XList.
2. Replace the half with the unsigned short data type.
parent 148b2577
...@@ -74,8 +74,9 @@ TensorListBase<T>::TensorListBase(int myMaxNum, XMem* myMem) ...@@ -74,8 +74,9 @@ TensorListBase<T>::TensorListBase(int myMaxNum, XMem* myMem)
template <typename T> template <typename T>
TensorListBase<T>::~TensorListBase() TensorListBase<T>::~TensorListBase()
{ {
if(items && mem) if(items)
delete[] items; delete[] items;
items = NULL;
} }
......
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
#include "core/getandset/SetData.h" #include "core/getandset/SetData.h"
#include "function/Identity.h" #include "function/Identity.h"
#include "core/CHeader.h" #include "core/CHeader.h"
//#include "XHalf.hpp"
#ifdef USE_CUDA #ifdef USE_CUDA
...@@ -1716,17 +1715,16 @@ void XTensor::Dump(FILE* file, const char* label, const int n, const int beg, co ...@@ -1716,17 +1715,16 @@ void XTensor::Dump(FILE* file, const char* label, const int n, const int beg, co
fprintf(file, " %d", f); fprintf(file, " %d", f);
} }
} }
/*else if (dataType == X_FLOAT16) { else if (dataType == X_FLOAT16) {
int end = MIN(n > 0 ? beg + n : beg + unitNum, unitNum); int end = MIN(n > 0 ? beg + n : beg + unitNum, unitNum);
for(int i = beg; i < end; i++){ for(int i = beg; i < end; i++){
DTYPE f = ((half_float::half*)d)[i]; DTYPE f = ((unsigned short*)d)[i];
if(i == beg) if(i == beg)
fprintf(file, "%e", f); fprintf(file, "%e", f);
else else
fprintf(file, " %e", f); fprintf(file, " %e", f);
} }
}*/ }
else else
ShowNTErrors("TODO!"); ShowNTErrors("TODO!");
} }
...@@ -1783,10 +1781,10 @@ void XTensor::BinaryDump(FILE* file) ...@@ -1783,10 +1781,10 @@ void XTensor::BinaryDump(FILE* file)
fwrite(tmp.data, sizeof(int), unitNum, file); fwrite(tmp.data, sizeof(int), unitNum, file);
break; break;
} }
/*case X_FLOAT16: { case X_FLOAT16: {
fwrite(tmp.data, sizeof(half_float::half), unitNum, file); fwrite(tmp.data, sizeof(unsigned short), unitNum, file);
break; break;
}*/ }
default: { default: {
fwrite(tmp.data, sizeof(float), unitNum, file); fwrite(tmp.data, sizeof(float), unitNum, file);
} }
...@@ -1920,13 +1918,13 @@ void XTensor::BinaryRead(FILE* file, size_t offset) ...@@ -1920,13 +1918,13 @@ void XTensor::BinaryRead(FILE* file, size_t offset)
delete[] d; delete[] d;
break; break;
} }
/*case X_FLOAT16: { case X_FLOAT16: {
half_float::half* d = new half_float::half[unitNum]; unsigned short* d = new unsigned short[unitNum];
fread(d, sizeof(half_float::half), unitNum, file); fread(d, sizeof(unsigned short), unitNum, file);
SetData(d, unitNum); SetData(d, unitNum);
delete[] d; delete[] d;
break; break;
}*/ }
default: { default: {
float* d = new float[unitNum]; float* d = new float[unitNum];
fread(d, sizeof(float), unitNum, file); fread(d, sizeof(float), unitNum, file);
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "ConvertDataType.h" #include "ConvertDataType.h"
#include "ConvertDataType.cuh" #include "ConvertDataType.cuh"
#include "../movement/CopyValues.h" #include "../movement/CopyValues.h"
//#include "../../XHalf.hpp"
namespace nts { // namespace nts(NiuTrans.Tensor) namespace nts { // namespace nts(NiuTrans.Tensor)
...@@ -93,18 +92,18 @@ void _ConvertDataType(const XTensor * input, XTensor * output) ...@@ -93,18 +92,18 @@ void _ConvertDataType(const XTensor * input, XTensor * output)
for (int i = 0; i < input->unitNum; i++) for (int i = 0; i < input->unitNum; i++)
outputData[i] = (float)inputData[i]; outputData[i] = (float)inputData[i];
} }
/*else if (input->dataType == X_FLOAT && output->dataType == X_FLOAT16) { else if (input->dataType == X_FLOAT && output->dataType == X_FLOAT16) {
float* inputData = (float*)input->data; float* inputData = (float*)input->data;
half_float::half* outputData = (half_float::half*)output->data; unsigned short* outputData = (unsigned short*)output->data;
for (int i = 0; i < input->unitNum; i++) for (int i = 0; i < input->unitNum; i++)
outputData[i] = (half_float::half)inputData[i]; outputData[i] = (unsigned short)inputData[i];
} }
else if (input->dataType == X_FLOAT16 && output->dataType == X_FLOAT) { else if (input->dataType == X_FLOAT16 && output->dataType == X_FLOAT) {
half_float::half* inputData = (half_float::half*)input->data; unsigned short* inputData = (unsigned short*)input->data;
float* outputData = (float*)output->data; float* outputData = (float*)output->data;
for (int i = 0; i < input->unitNum; i++) for (int i = 0; i < input->unitNum; i++)
outputData[i] = (float)inputData[i]; outputData[i] = (float)inputData[i];
}*/ }
else else
ShowNTErrors("Unsupported data types for conversion!"); ShowNTErrors("Unsupported data types for conversion!");
} }
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "SetData.cuh" #include "SetData.cuh"
#include "../../XUtility.h" #include "../../XUtility.h"
#include "../movement/CopyValues.h" #include "../movement/CopyValues.h"
//#include "../../XHalf.hpp"
#if !defined( WIN32 ) && !defined( _WIN32 ) #if !defined( WIN32 ) && !defined( _WIN32 )
#include "sys/time.h" #include "sys/time.h"
...@@ -438,12 +437,12 @@ void _SetDataRand(XTensor * tensor, DTYPE lower, DTYPE upper) ...@@ -438,12 +437,12 @@ void _SetDataRand(XTensor * tensor, DTYPE lower, DTYPE upper)
d[i] = variance * ((float)rand()/RAND_MAX) + lower; d[i] = variance * ((float)rand()/RAND_MAX) + lower;
} }
} }
/*else if (tensor->dataType == X_FLOAT16) { else if (tensor->dataType == X_FLOAT16) {
half_float::half* d = (half_float::half*)tensor->data; unsigned short* d = (unsigned short*)tensor->data;
for (int i = 0; i < tensor->unitNum; i++) { for (int i = 0; i < tensor->unitNum; i++) {
d[i] = variance * ((half_float::half)rand() / RAND_MAX) + lower; d[i] = variance * ((unsigned short)rand() / RAND_MAX) + lower;
} }
}*/ }
else if(tensor->dataType == X_DOUBLE){ else if(tensor->dataType == X_DOUBLE){
double * d = (double*)tensor->data; double * d = (double*)tensor->data;
for(int i = 0; i < tensor->unitNum; i++){ for(int i = 0; i < tensor->unitNum; i++){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论