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
gaoqiong
flash-attention
Commits
d9cbcfb4
Commit
d9cbcfb4
authored
Jan 13, 2024
by
Tri Dao
Browse files
Remove dead code in philox.cuh
parent
a7b66ae2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
114 deletions
+0
-114
csrc/flash_attn/src/philox.cuh
csrc/flash_attn/src/philox.cuh
+0
-114
No files found.
csrc/flash_attn/src/philox.cuh
View file @
d9cbcfb4
...
...
@@ -49,117 +49,3 @@ inline __device__ uint4 philox(unsigned long long seed,
}
}
// namespace flash
namespace
{
class
Philox
{
public:
__device__
inline
Philox
(
unsigned
long
long
seed
,
unsigned
long
long
subsequence
,
unsigned
long
long
offset
)
:
STATE
(
0
)
,
seed_
(
seed
)
,
offset_
(
offset
)
,
key
(
reinterpret_cast
<
const
uint2
&>
(
seed
))
{
//key.x = (unsigned int)seed;
//key.y = (unsigned int)(seed >> 32);
//counter = make_uint4(0, 0, 0, 0);
//counter.z = (unsigned int)(subsequence);
//counter.w = (unsigned int)(subsequence >> 32);
//STATE = 0;
//incr_n(offset / 4);
// key = reinterpret_cast<const uint2&>(seed);
ull2
*
tmp
=
reinterpret_cast
<
ull2
*>
(
&
counter
);
tmp
->
x
=
offset
/
4
;
tmp
->
y
=
subsequence
;
// if ((threadIdx.x == 0) && (blockIdx.x == 0) && (blockIdx.y == 0)) {
// printf("Philox counter: %d, %d, %d, %d\n", counter.x, counter.y, counter.z, counter.w);
// }
}
__device__
inline
uint4
operator
()()
{
// // if (STATE == 0) {
// uint4 counter_ = counter;
// uint2 key_ = key;
// // 7-round philox
// #pragma unroll
// for (int i = 0; i < 6; i++) {
// counter_ = flash::philox_single_round(counter_, key_);
// key_.x += (kPhilox10A);
// key_.y += (kPhilox10B);
// }
// // output = philox_single_round(counter_, key_);
// uint4 output = flash::philox_single_round(counter_, key_);
// // if ((threadIdx.x == 0) && (blockIdx.x == 0) && (blockIdx.y == 0)) {
// // printf("Philox counter: %u, %u, %u, %u\n", counter.x, counter.y, counter.z, counter.w);
// // printf("Philox output: %u, %u, %u, %u\n", output.x, output.y, output.z, output.w);
// // }
// incr();
// // }
// // return a float4 directly
// // unsigned long ret;
// // switch(STATE) {
// // case 0: ret = output.x; break;
// // case 1: ret = output.y; break;
// // case 2: ret = output.z; break;
// // case 3: ret = output.w; break;
// //}
// // STATE = (STATE + 1) % 4;
// return output;
return
flash
::
philox
(
seed_
,
offset_
,
offset_
);
}
private:
unsigned
long
long
offset_
,
seed_
;
struct
ull2
{
uint64_t
x
;
uint64_t
y
;
};
uint4
counter
;
// uint4 output;
const
uint2
key
;
unsigned
int
STATE
;
__device__
inline
void
incr_n
(
unsigned
long
long
n
)
{
unsigned
int
nlo
=
(
unsigned
int
)(
n
);
unsigned
int
nhi
=
(
unsigned
int
)(
n
>>
32
);
counter
.
x
+=
nlo
;
if
(
counter
.
x
<
nlo
)
nhi
++
;
counter
.
y
+=
nhi
;
if
(
nhi
<=
counter
.
y
)
return
;
if
(
++
counter
.
z
)
return
;
++
counter
.
w
;
}
__device__
uint4
incr128
(
uint4
ctr
)
{
uint4
res
;
asm
(
"add.cc.u32 %0, %4, %8;
\n\t
"
"addc.cc.u32 %1, %5, %9;
\n\t
"
"addc.cc.u32 %2, %6, %10;
\n\t
"
"addc.u32 %3, %7, %11;
\n\t
"
:
"=r"
(
res
.
x
),
"=r"
(
res
.
y
),
"=r"
(
res
.
z
),
"=r"
(
res
.
w
)
:
"r"
(
ctr
.
x
),
"r"
(
ctr
.
y
),
"r"
(
ctr
.
z
),
"r"
(
ctr
.
w
),
"n"
(
1
),
"n"
(
0
),
"n"
(
0
),
"n"
(
0
));
return
res
;
}
__device__
inline
void
incr
()
{
// if ((threadIdx.x == 0) && (blockIdx.x == 0) && (blockIdx.y == 0)) {
// printf("Counter before: %u, %u, %u, %u\n", counter.x, counter.y, counter.z, counter.w);
// }
counter
=
incr128
(
counter
);
// if ((threadIdx.x == 0) && (blockIdx.x == 0) && (blockIdx.y == 0)) {
// printf("Counter after: %u, %u, %u, %u\n", counter.x, counter.y, counter.z, counter.w);
// }
}
static
const
unsigned
long
kPhilox10A
=
0x9E3779B9
;
static
const
unsigned
long
kPhilox10B
=
0xBB67AE85
;
// static const unsigned long kPhiloxSA = 0xD2511F53;
// static const unsigned long kPhiloxSB = 0xCD9E8D57;
};
}
// namespace
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