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