Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
64c94cb2
Commit
64c94cb2
authored
Dec 19, 2013
by
Alexander Smorkalov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CUDA related func tables refactored to remove unneeded dependencies.
parent
6da7c50f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
74 deletions
+68
-74
gpumat.cpp
modules/core/src/gpumat.cpp
+15
-15
gpumat_cuda.hpp
modules/core/src/gpumat_cuda.hpp
+53
-59
No files found.
modules/core/src/gpumat.cpp
View file @
64c94cb2
...
...
@@ -239,23 +239,23 @@ static DeviceInfoFuncTable* deviceInfoFuncTable()
//////////////////////////////// Initialization & Info ////////////////////////
int
cv
::
gpu
::
getCudaEnabledDeviceCount
()
{
return
gpu
FuncTable
()
->
getCudaEnabledDeviceCount
();
}
int
cv
::
gpu
::
getCudaEnabledDeviceCount
()
{
return
deviceInfo
FuncTable
()
->
getCudaEnabledDeviceCount
();
}
void
cv
::
gpu
::
setDevice
(
int
device
)
{
gpu
FuncTable
()
->
setDevice
(
device
);
}
int
cv
::
gpu
::
getDevice
()
{
return
gpu
FuncTable
()
->
getDevice
();
}
void
cv
::
gpu
::
setDevice
(
int
device
)
{
deviceInfo
FuncTable
()
->
setDevice
(
device
);
}
int
cv
::
gpu
::
getDevice
()
{
return
deviceInfo
FuncTable
()
->
getDevice
();
}
void
cv
::
gpu
::
resetDevice
()
{
gpu
FuncTable
()
->
resetDevice
();
}
void
cv
::
gpu
::
resetDevice
()
{
deviceInfo
FuncTable
()
->
resetDevice
();
}
bool
cv
::
gpu
::
deviceSupports
(
FeatureSet
feature_set
)
{
return
gpu
FuncTable
()
->
deviceSupports
(
feature_set
);
}
bool
cv
::
gpu
::
deviceSupports
(
FeatureSet
feature_set
)
{
return
deviceInfo
FuncTable
()
->
deviceSupports
(
feature_set
);
}
bool
cv
::
gpu
::
TargetArchs
::
builtWith
(
FeatureSet
feature_set
)
{
return
gpu
FuncTable
()
->
builtWith
(
feature_set
);
}
bool
cv
::
gpu
::
TargetArchs
::
has
(
int
major
,
int
minor
)
{
return
gpu
FuncTable
()
->
has
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasPtx
(
int
major
,
int
minor
)
{
return
gpu
FuncTable
()
->
hasPtx
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasBin
(
int
major
,
int
minor
)
{
return
gpu
FuncTable
()
->
hasBin
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasEqualOrLessPtx
(
int
major
,
int
minor
)
{
return
gpu
FuncTable
()
->
hasEqualOrLessPtx
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasEqualOrGreater
(
int
major
,
int
minor
)
{
return
gpu
FuncTable
()
->
hasEqualOrGreater
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasEqualOrGreaterPtx
(
int
major
,
int
minor
)
{
return
gpu
FuncTable
()
->
hasEqualOrGreaterPtx
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasEqualOrGreaterBin
(
int
major
,
int
minor
)
{
return
gpu
FuncTable
()
->
hasEqualOrGreaterBin
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
builtWith
(
FeatureSet
feature_set
)
{
return
deviceInfo
FuncTable
()
->
builtWith
(
feature_set
);
}
bool
cv
::
gpu
::
TargetArchs
::
has
(
int
major
,
int
minor
)
{
return
deviceInfo
FuncTable
()
->
has
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasPtx
(
int
major
,
int
minor
)
{
return
deviceInfo
FuncTable
()
->
hasPtx
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasBin
(
int
major
,
int
minor
)
{
return
deviceInfo
FuncTable
()
->
hasBin
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasEqualOrLessPtx
(
int
major
,
int
minor
)
{
return
deviceInfo
FuncTable
()
->
hasEqualOrLessPtx
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasEqualOrGreater
(
int
major
,
int
minor
)
{
return
deviceInfo
FuncTable
()
->
hasEqualOrGreater
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasEqualOrGreaterPtx
(
int
major
,
int
minor
)
{
return
deviceInfo
FuncTable
()
->
hasEqualOrGreaterPtx
(
major
,
minor
);
}
bool
cv
::
gpu
::
TargetArchs
::
hasEqualOrGreaterBin
(
int
major
,
int
minor
)
{
return
deviceInfo
FuncTable
()
->
hasEqualOrGreaterBin
(
major
,
minor
);
}
size_t
cv
::
gpu
::
DeviceInfo
::
sharedMemPerBlock
()
const
{
return
deviceInfoFuncTable
()
->
sharedMemPerBlock
();
}
void
cv
::
gpu
::
DeviceInfo
::
queryMemory
(
size_t
&
total_memory
,
size_t
&
free_memory
)
const
{
deviceInfoFuncTable
()
->
queryMemory
(
total_memory
,
free_memory
);
}
...
...
@@ -270,8 +270,8 @@ std::string cv::gpu::DeviceInfo::name() const { return deviceInfoFuncTable()->na
int
cv
::
gpu
::
DeviceInfo
::
multiProcessorCount
()
const
{
return
deviceInfoFuncTable
()
->
multiProcessorCount
();
}
void
cv
::
gpu
::
DeviceInfo
::
query
()
{
deviceInfoFuncTable
()
->
query
();
}
void
cv
::
gpu
::
printCudaDeviceInfo
(
int
device
)
{
gpu
FuncTable
()
->
printCudaDeviceInfo
(
device
);
}
void
cv
::
gpu
::
printShortCudaDeviceInfo
(
int
device
)
{
gpu
FuncTable
()
->
printShortCudaDeviceInfo
(
device
);
}
void
cv
::
gpu
::
printCudaDeviceInfo
(
int
device
)
{
deviceInfo
FuncTable
()
->
printCudaDeviceInfo
(
device
);
}
void
cv
::
gpu
::
printShortCudaDeviceInfo
(
int
device
)
{
deviceInfo
FuncTable
()
->
printShortCudaDeviceInfo
(
device
);
}
#ifdef HAVE_CUDA
...
...
modules/core/src/gpumat_cuda.hpp
View file @
64c94cb2
...
...
@@ -4,6 +4,7 @@
class
DeviceInfoFuncTable
{
public
:
// cv::DeviceInfo
virtual
size_t
sharedMemPerBlock
()
const
=
0
;
virtual
void
queryMemory
(
size_t
&
,
size_t
&
)
const
=
0
;
virtual
size_t
freeMemory
()
const
=
0
;
...
...
@@ -16,25 +17,13 @@
virtual
int
majorVersion
()
const
=
0
;
virtual
int
minorVersion
()
const
=
0
;
virtual
int
multiProcessorCount
()
const
=
0
;
virtual
~
DeviceInfoFuncTable
()
{};
};
class
GpuFuncTable
{
public
:
virtual
~
GpuFuncTable
()
{}
// DeviceInfo routines
virtual
int
getCudaEnabledDeviceCount
()
const
=
0
;
virtual
void
setDevice
(
int
)
const
=
0
;
virtual
int
getDevice
()
const
=
0
;
virtual
void
resetDevice
()
const
=
0
;
virtual
bool
deviceSupports
(
FeatureSet
)
const
=
0
;
// TargetArchs
//
cv::
TargetArchs
virtual
bool
builtWith
(
FeatureSet
)
const
=
0
;
virtual
bool
has
(
int
,
int
)
const
=
0
;
virtual
bool
hasPtx
(
int
,
int
)
const
=
0
;
...
...
@@ -47,6 +36,14 @@
virtual
void
printCudaDeviceInfo
(
int
)
const
=
0
;
virtual
void
printShortCudaDeviceInfo
(
int
)
const
=
0
;
virtual
~
DeviceInfoFuncTable
()
{};
};
class
GpuFuncTable
{
public
:
virtual
~
GpuFuncTable
()
{}
// GpuMat routines
virtual
void
copy
(
const
Mat
&
src
,
GpuMat
&
dst
)
const
=
0
;
virtual
void
copy
(
const
GpuMat
&
src
,
Mat
&
dst
)
const
=
0
;
...
...
@@ -80,13 +77,7 @@
int
majorVersion
()
const
{
throw_nogpu
;
return
-
1
;
}
int
minorVersion
()
const
{
throw_nogpu
;
return
-
1
;
}
int
multiProcessorCount
()
const
{
throw_nogpu
;
return
-
1
;
}
};
class
EmptyFuncTable
:
public
GpuFuncTable
{
public
:
// DeviceInfo routines
int
getCudaEnabledDeviceCount
()
const
{
return
0
;
}
void
setDevice
(
int
)
const
{
throw_nogpu
;
}
...
...
@@ -107,6 +98,11 @@
void
printCudaDeviceInfo
(
int
)
const
{
throw_nogpu
;
}
void
printShortCudaDeviceInfo
(
int
)
const
{
throw_nogpu
;
}
};
class
EmptyFuncTable
:
public
GpuFuncTable
{
public
:
void
copy
(
const
Mat
&
,
GpuMat
&
)
const
{
throw_nogpu
;
}
void
copy
(
const
GpuMat
&
,
Mat
&
)
const
{
throw_nogpu
;
}
...
...
@@ -568,12 +564,12 @@ namespace cv { namespace gpu { namespace device
bool
isCompatible
()
const
{
// Check PTX compatibility
if
(
TargetArchs
::
hasEqualOrLessPtx
(
majorVersion_
,
minorVersion_
))
if
(
hasEqualOrLessPtx
(
majorVersion_
,
minorVersion_
))
return
true
;
// Check BIN compatibility
for
(
int
i
=
minorVersion_
;
i
>=
0
;
--
i
)
if
(
TargetArchs
::
hasBin
(
majorVersion_
,
i
))
if
(
hasBin
(
majorVersion_
,
i
))
return
true
;
return
false
;
...
...
@@ -614,44 +610,6 @@ namespace cv { namespace gpu { namespace device
return
multi_processor_count_
;
}
private
:
int
device_id_
;
std
::
string
name_
;
int
multi_processor_count_
;
int
majorVersion_
;
int
minorVersion_
;
};
class
CudaFuncTable
:
public
GpuFuncTable
{
protected
:
const
CudaArch
cudaArch
;
int
convertSMVer2Cores
(
int
major
,
int
minor
)
const
{
// Defines for GPU Architecture types (using the SM version to determine the # of cores per SM
typedef
struct
{
int
SM
;
// 0xMm (hexidecimal notation), M = SM Major version, and m = SM minor version
int
Cores
;
}
SMtoCores
;
SMtoCores
gpuArchCoresPerSM
[]
=
{
{
0x10
,
8
},
{
0x11
,
8
},
{
0x12
,
8
},
{
0x13
,
8
},
{
0x20
,
32
},
{
0x21
,
48
},
{
0x30
,
192
},
{
0x35
,
192
},
{
-
1
,
-
1
}
};
int
index
=
0
;
while
(
gpuArchCoresPerSM
[
index
].
SM
!=
-
1
)
{
if
(
gpuArchCoresPerSM
[
index
].
SM
==
((
major
<<
4
)
+
minor
)
)
return
gpuArchCoresPerSM
[
index
].
Cores
;
index
++
;
}
return
-
1
;
}
public
:
int
getCudaEnabledDeviceCount
()
const
{
int
count
;
...
...
@@ -859,6 +817,42 @@ namespace cv { namespace gpu { namespace device
fflush
(
stdout
);
}
private
:
int
device_id_
;
std
::
string
name_
;
int
multi_processor_count_
;
int
majorVersion_
;
int
minorVersion_
;
const
CudaArch
cudaArch
;
int
convertSMVer2Cores
(
int
major
,
int
minor
)
const
{
// Defines for GPU Architecture types (using the SM version to determine the # of cores per SM
typedef
struct
{
int
SM
;
// 0xMm (hexidecimal notation), M = SM Major version, and m = SM minor version
int
Cores
;
}
SMtoCores
;
SMtoCores
gpuArchCoresPerSM
[]
=
{
{
0x10
,
8
},
{
0x11
,
8
},
{
0x12
,
8
},
{
0x13
,
8
},
{
0x20
,
32
},
{
0x21
,
48
},
{
0x30
,
192
},
{
0x35
,
192
},
{
-
1
,
-
1
}
};
int
index
=
0
;
while
(
gpuArchCoresPerSM
[
index
].
SM
!=
-
1
)
{
if
(
gpuArchCoresPerSM
[
index
].
SM
==
((
major
<<
4
)
+
minor
)
)
return
gpuArchCoresPerSM
[
index
].
Cores
;
index
++
;
}
return
-
1
;
}
};
class
CudaFuncTable
:
public
GpuFuncTable
{
public
:
void
copy
(
const
Mat
&
src
,
GpuMat
&
dst
)
const
{
cudaSafeCall
(
cudaMemcpy2D
(
dst
.
data
,
dst
.
step
,
src
.
data
,
src
.
step
,
src
.
cols
*
src
.
elemSize
(),
src
.
rows
,
cudaMemcpyHostToDevice
)
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment