Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
df78bb3c
"git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "28e0e6f0d599178c4cd3c8d186ac7064da19784f"
Commit
df78bb3c
authored
Oct 26, 2016
by
Guolin Ke
Committed by
GitHub
Oct 26, 2016
Browse files
Fix LRU pool slow when cache is enough
parent
656ff6f3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
18 deletions
+28
-18
include/LightGBM/utils/lru_pool.h
include/LightGBM/utils/lru_pool.h
+28
-18
No files found.
include/LightGBM/utils/lru_pool.h
View file @
df78bb3c
...
@@ -38,32 +38,32 @@ public:
...
@@ -38,32 +38,32 @@ public:
cache_size_
=
cache_size
;
cache_size_
=
cache_size
;
// at least need 2 bucket to store smaller leaf and larger leaf
// at least need 2 bucket to store smaller leaf and larger leaf
CHECK
(
cache_size_
>=
2
);
CHECK
(
cache_size_
>=
2
);
total_size_
=
total_size
;
total_size_
=
total_size
;
if
(
cache_size_
>
total_size_
)
{
pool_
=
new
T
[
cache_size
];
cache_size_
=
total_size_
;
}
is_enough_
=
(
cache_size_
==
total_size_
);
pool_
=
new
T
[
cache_size_
];
if
(
!
is_enough_
)
{
mapper_
=
new
int
[
total_size_
];
mapper_
=
new
int
[
total_size_
];
inverse_mapper_
=
new
int
[
cache_size_
];
inverse_mapper_
=
new
int
[
cache_size_
];
last_used_time_
=
new
int
[
cache_size_
];
last_used_time_
=
new
int
[
cache_size_
];
ResetMap
();
ResetMap
();
}
}
/*!
* \brief Return true if this pool is enough to store all data
*/
bool
IsEnough
()
{
return
cache_size_
==
total_size_
;
}
}
/*!
/*!
* \brief Reset mapper
* \brief Reset mapper
*/
*/
void
ResetMap
()
{
void
ResetMap
()
{
if
(
!
is_enough_
)
{
cur_time_
=
0
;
cur_time_
=
0
;
memset
(
mapper_
,
-
1
,
sizeof
(
int
)
*
total_size_
);
memset
(
mapper_
,
-
1
,
sizeof
(
int
)
*
total_size_
);
memset
(
inverse_mapper_
,
-
1
,
sizeof
(
int
)
*
cache_size_
);
memset
(
inverse_mapper_
,
-
1
,
sizeof
(
int
)
*
cache_size_
);
memset
(
last_used_time_
,
0
,
sizeof
(
int
)
*
cache_size_
);
memset
(
last_used_time_
,
0
,
sizeof
(
int
)
*
cache_size_
);
}
}
}
/*!
/*!
* \brief Set data for the pool for specific index
* \brief Set data for the pool for specific index
...
@@ -81,7 +81,11 @@ public:
...
@@ -81,7 +81,11 @@ public:
* \return True if this index is in the pool, False if this index is not in the pool
* \return True if this index is in the pool, False if this index is not in the pool
*/
*/
bool
Get
(
int
idx
,
T
*
out
)
{
bool
Get
(
int
idx
,
T
*
out
)
{
if
(
mapper_
[
idx
]
>=
0
)
{
if
(
is_enough_
)
{
*
out
=
pool_
[
idx
];
return
true
;
}
else
if
(
mapper_
[
idx
]
>=
0
)
{
int
slot
=
mapper_
[
idx
];
int
slot
=
mapper_
[
idx
];
*
out
=
pool_
[
slot
];
*
out
=
pool_
[
slot
];
last_used_time_
[
slot
]
=
++
cur_time_
;
last_used_time_
[
slot
]
=
++
cur_time_
;
...
@@ -108,6 +112,10 @@ public:
...
@@ -108,6 +112,10 @@ public:
* \param dst_idx
* \param dst_idx
*/
*/
void
Move
(
int
src_idx
,
int
dst_idx
)
{
void
Move
(
int
src_idx
,
int
dst_idx
)
{
if
(
is_enough_
)
{
std
::
swap
(
pool_
[
src_idx
],
pool_
[
dst_idx
]);
return
;
}
if
(
mapper_
[
src_idx
]
<
0
)
{
if
(
mapper_
[
src_idx
]
<
0
)
{
return
;
return
;
}
}
...
@@ -122,6 +130,7 @@ public:
...
@@ -122,6 +130,7 @@ public:
inverse_mapper_
[
slot
]
=
dst_idx
;
inverse_mapper_
[
slot
]
=
dst_idx
;
}
}
private:
private:
void
FreeAll
(){
void
FreeAll
(){
if
(
pool_
!=
nullptr
)
{
if
(
pool_
!=
nullptr
)
{
delete
[]
pool_
;
delete
[]
pool_
;
...
@@ -139,6 +148,7 @@ private:
...
@@ -139,6 +148,7 @@ private:
T
*
pool_
=
nullptr
;
T
*
pool_
=
nullptr
;
int
cache_size_
;
int
cache_size_
;
int
total_size_
;
int
total_size_
;
bool
is_enough_
=
false
;
int
*
mapper_
=
nullptr
;
int
*
mapper_
=
nullptr
;
int
*
inverse_mapper_
=
nullptr
;
int
*
inverse_mapper_
=
nullptr
;
int
*
last_used_time_
=
nullptr
;
int
*
last_used_time_
=
nullptr
;
...
...
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