Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
a7660331a
tesseract
提交
1e5522d3
T
tesseract
项目概览
a7660331a
/
tesseract
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tesseract
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1e5522d3
编写于
6月 03, 2017
作者:
Z
zdenop
提交者:
GitHub
6月 03, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #975 from stweil/ocl
Clean OpenCL code
上级
34bdf997
1bbcbd89
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
68 deletion
+9
-68
opencl/openclwrapper.cpp
opencl/openclwrapper.cpp
+9
-68
未找到文件。
opencl/openclwrapper.cpp
浏览文件 @
1e5522d3
...
...
@@ -58,27 +58,6 @@ static const l_uint32 rmask32[] = {
0x01ffffff
,
0x03ffffff
,
0x07ffffff
,
0x0fffffff
,
0x1fffffff
,
0x3fffffff
,
0x7fffffff
,
0xffffffff
};
struct
tiff_transform
{
int
vflip
;
/* if non-zero, image needs a vertical fip */
int
hflip
;
/* if non-zero, image needs a horizontal flip */
int
rotate
;
/* -1 -> counterclockwise 90-degree rotation,
0 -> no rotation
1 -> clockwise 90-degree rotation */
};
static
struct
tiff_transform
tiff_orientation_transforms
[]
=
{
{
0
,
0
,
0
},
{
0
,
1
,
0
},
{
1
,
1
,
0
},
{
1
,
0
,
0
},
{
0
,
1
,
-
1
},
{
0
,
0
,
1
},
{
0
,
1
,
1
},
{
0
,
0
,
-
1
}
};
static
const
l_int32
MAX_PAGES_IN_TIFF_FILE
=
3000
;
static
cl_mem
pixsCLBuffer
,
pixdCLBuffer
,
pixdCLIntermediate
;
//Morph operations buffers
static
cl_mem
pixThBuffer
;
//output from thresholdtopix calculation
static
cl_int
clStatus
;
...
...
@@ -351,7 +330,6 @@ static ds_status readProfileFromFile(ds_profile *profile,
const
char
*
currentPosition
;
const
char
*
dataStart
;
const
char
*
dataEnd
;
size_t
versionStringLength
;
contentEnd
=
contentStart
+
contentSize
;
currentPosition
=
contentStart
;
...
...
@@ -370,8 +348,8 @@ static ds_status readProfileFromFile(ds_profile *profile,
goto
cleanup
;
}
versionStringLength
=
strlen
(
profile
->
version
);
if
(
versionStringLength
!=
(
dataEnd
-
dataStart
)
||
size_t
versionStringLength
=
strlen
(
profile
->
version
);
if
(
versionStringLength
+
dataStart
!=
dataEnd
||
strncmp
(
profile
->
version
,
dataStart
,
versionStringLength
)
!=
0
)
{
// version mismatch
status
=
DS_PROFILE_FILE_ERROR
;
...
...
@@ -460,8 +438,8 @@ static ds_status readProfileFromFile(ds_profile *profile,
actualDeviceNameLength
=
strlen
(
profile
->
devices
[
i
].
oclDeviceName
);
driverVersionLength
=
strlen
(
profile
->
devices
[
i
].
oclDriverVersion
);
if
(
actualDeviceNameLength
==
(
deviceNameEnd
-
deviceNameStart
)
&&
d
riverVersionLength
==
(
deviceDriverEnd
-
deviceDriverStart
)
&&
if
(
deviceNameStart
+
actualDeviceNameLength
==
deviceNameEnd
&&
d
eviceDriverStart
+
driverVersionLength
==
deviceDriverEnd
&&
strncmp
(
profile
->
devices
[
i
].
oclDeviceName
,
deviceNameStart
,
actualDeviceNameLength
)
==
0
&&
strncmp
(
profile
->
devices
[
i
].
oclDriverVersion
,
deviceDriverStart
,
...
...
@@ -607,7 +585,7 @@ static void legalizeFileName( char *fileName) {
const
char
*
invalidChars
=
"/\?:*
\"
><| "
;
// space is valid but can cause headaches
// for each invalid char
for
(
int
i
=
0
;
i
<
strlen
(
invalidChars
);
i
++
)
{
for
(
unsigned
i
=
0
;
i
<
strlen
(
invalidChars
);
i
++
)
{
char
invalidStr
[
4
];
invalidStr
[
0
]
=
invalidChars
[
i
];
invalidStr
[
1
]
=
'\0'
;
...
...
@@ -727,31 +705,6 @@ Pix *mapOutputCLBuffer(KernelEnv rEnv, cl_mem clbuffer, Pix *pixd, Pix *pixs,
return
pixd
;
}
static
cl_mem
allocateIntBuffer
(
KernelEnv
rEnv
,
const
l_uint32
*
_pValues
,
size_t
nElements
,
cl_int
*
pStatus
,
bool
sync
=
false
)
{
cl_mem
xValues
=
clCreateBuffer
(
rEnv
.
mpkContext
,
(
cl_mem_flags
)(
CL_MEM_READ_WRITE
),
nElements
*
sizeof
(
l_int32
),
nullptr
,
pStatus
);
if
(
_pValues
!=
nullptr
)
{
l_int32
*
pValues
=
(
l_int32
*
)
clEnqueueMapBuffer
(
rEnv
.
mpkCmdQueue
,
xValues
,
CL_TRUE
,
CL_MAP_WRITE
,
0
,
nElements
*
sizeof
(
l_int32
),
0
,
nullptr
,
nullptr
,
nullptr
);
memcpy
(
pValues
,
_pValues
,
nElements
*
sizeof
(
l_int32
));
clEnqueueUnmapMemObject
(
rEnv
.
mpkCmdQueue
,
xValues
,
pValues
,
0
,
nullptr
,
nullptr
);
if
(
sync
)
clFinish
(
rEnv
.
mpkCmdQueue
);
}
return
xValues
;
}
void
OpenclDevice
::
releaseMorphCLBuffers
()
{
if
(
pixdCLIntermediate
!=
nullptr
)
clReleaseMemObject
(
pixdCLIntermediate
);
...
...
@@ -1851,7 +1804,6 @@ int OpenclDevice::HistogramRectOCL(unsigned char *imageData,
static_cast
<
size_t
>
(
block_size
*
kHistogramSize
*
bytes_per_pixel
)};
/* map histogramAllChannels as write only */
int
numBins
=
kHistogramSize
*
bytes_per_pixel
*
numWorkGroups
;
cl_mem
histogramBuffer
=
clCreateBuffer
(
histKern
.
mpkContext
,
CL_MEM_READ_WRITE
|
CL_MEM_USE_HOST_PTR
,
...
...
@@ -2046,7 +1998,6 @@ int OpenclDevice::ThresholdRectToPixOCL(unsigned char *imageData,
/* set kernel arguments */
clStatus
=
clSetKernelArg
(
rEnv
.
mpkKernel
,
0
,
sizeof
(
cl_mem
),
&
imageBuffer
);
CHECK_OPENCL
(
clStatus
,
"clSetKernelArg imageBuffer"
);
cl_uint
numPixels
=
width
*
height
;
clStatus
=
clSetKernelArg
(
rEnv
.
mpkKernel
,
1
,
sizeof
(
int
),
&
height
);
CHECK_OPENCL
(
clStatus
,
"clSetKernelArg height"
);
clStatus
=
clSetKernelArg
(
rEnv
.
mpkKernel
,
2
,
sizeof
(
int
),
&
width
);
...
...
@@ -2243,9 +2194,6 @@ static double composeRGBPixelMicroBench(GPUEnv *env, TessScoreEvaluationInputDat
#endif
Pix
*
pix
=
pixCreate
(
input
.
width
,
input
.
height
,
32
);
l_uint32
*
pixData
=
pixGetData
(
pix
);
int
wpl
=
pixGetWpl
(
pix
);
//l_uint32* output_gpu=pixReadFromTiffKernel(tiffdata,w,h,wpl,line);
//pixSetData(pix, output_gpu);
int
i
,
j
;
int
idx
=
0
;
for
(
i
=
0
;
i
<
input
.
height
;
i
++
)
{
...
...
@@ -2291,14 +2239,11 @@ static double histogramRectMicroBench( GPUEnv *env, TessScoreEvaluationInputData
timespec
time_funct_start
,
time_funct_end
;
#endif
unsigned
char
pixelHi
=
(
unsigned
char
)
255
;
int
left
=
0
;
int
top
=
0
;
int
kHistogramSize
=
256
;
int
bytes_per_line
=
input
.
width
*
input
.
numChannels
;
int
*
histogramAllChannels
=
new
int
[
kHistogramSize
*
input
.
numChannels
];
int
retVal
=
0
;
// function call
if
(
type
==
DS_DEVICE_OPENCL_DEVICE
)
{
#if ON_WINDOWS
...
...
@@ -2310,8 +2255,7 @@ static double histogramRectMicroBench( GPUEnv *env, TessScoreEvaluationInputData
#endif
OpenclDevice
::
gpuEnv
=
*
env
;
int
wpl
=
pixGetWpl
(
input
.
pix
);
retVal
=
OpenclDevice
::
HistogramRectOCL
(
int
retVal
=
OpenclDevice
::
HistogramRectOCL
(
input
.
imageData
,
input
.
numChannels
,
bytes_per_line
,
top
,
left
,
input
.
width
,
input
.
height
,
kHistogramSize
,
histogramAllChannels
);
...
...
@@ -2400,7 +2344,6 @@ static void ThresholdRectToPix_Native(const unsigned char* imagedata,
static
double
thresholdRectToPixMicroBench
(
GPUEnv
*
env
,
TessScoreEvaluationInputData
input
,
ds_device_type
type
)
{
double
time
;
int
retVal
=
0
;
#if ON_WINDOWS
LARGE_INTEGER
freq
,
time_funct_start
,
time_funct_end
;
QueryPerformanceFrequency
(
&
freq
);
...
...
@@ -2440,8 +2383,7 @@ static double thresholdRectToPixMicroBench(GPUEnv *env, TessScoreEvaluationInput
#endif
OpenclDevice
::
gpuEnv
=
*
env
;
int
wpl
=
pixGetWpl
(
input
.
pix
);
retVal
=
OpenclDevice
::
ThresholdRectToPixOCL
(
int
retVal
=
OpenclDevice
::
ThresholdRectToPixOCL
(
input
.
imageData
,
input
.
numChannels
,
bytes_per_line
,
thresholds
,
hi_values
,
&
input
.
pix
,
input
.
height
,
input
.
width
,
top
,
left
);
...
...
@@ -2526,7 +2468,6 @@ static double getLineMasksMorphMicroBench(GPUEnv *env, TessScoreEvaluationInputD
#else
clock_gettime
(
CLOCK_MONOTONIC
,
&
time_funct_start
);
#endif
Pix
*
src_pix
=
input
.
pix
;
OpenclDevice
::
gpuEnv
=
*
env
;
OpenclDevice
::
initMorphCLAllocations
(
wpl
,
input
.
height
,
input
.
pix
);
Pix
*
pix_vline
=
nullptr
,
*
pix_hline
=
nullptr
,
*
pix_closed
=
nullptr
;
...
...
@@ -2723,12 +2664,12 @@ ds_device OpenclDevice::getDeviceSelection( ) {
// select fastest using custom Tesseract selection algorithm
float
bestTime
=
FLT_MAX
;
// begin search with worst possible time
int
bestDeviceIdx
=
-
1
;
for
(
int
d
=
0
;
d
<
profile
->
numDevices
;
d
++
)
{
for
(
unsigned
d
=
0
;
d
<
profile
->
numDevices
;
d
++
)
{
ds_device
device
=
profile
->
devices
[
d
];
TessDeviceScore
score
=
*
(
TessDeviceScore
*
)
device
.
score
;
float
time
=
score
.
time
;
printf
(
"[DS] Device[%
i
] %i:%s score is %f
\n
"
,
d
+
1
,
device
.
type
,
printf
(
"[DS] Device[%
u
] %i:%s score is %f
\n
"
,
d
+
1
,
device
.
type
,
device
.
oclDeviceName
,
time
);
if
(
time
<
bestTime
)
{
bestTime
=
time
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录