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
composable_kernel_ROCM
Commits
71d6ede7
Commit
71d6ede7
authored
Jan 05, 2024
by
Jun Liu
Browse files
Merge branch 'develop' into amd-develop
parents
f4855e8c
22db1e08
Changes
45
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
273 additions
and
17 deletions
+273
-17
test/wrapper/CMakeLists.txt
test/wrapper/CMakeLists.txt
+4
-0
test/wrapper/test_copy.cpp
test/wrapper/test_copy.cpp
+129
-0
test/wrapper/test_layout.cpp
test/wrapper/test_layout.cpp
+2
-9
test/wrapper/test_partition.cpp
test/wrapper/test_partition.cpp
+119
-0
test/wrapper/test_tensor.cpp
test/wrapper/test_tensor.cpp
+19
-8
No files found.
test/wrapper/CMakeLists.txt
View file @
71d6ede7
...
@@ -2,3 +2,7 @@ add_gtest_executable(test_layout test_layout.cpp)
...
@@ -2,3 +2,7 @@ add_gtest_executable(test_layout test_layout.cpp)
target_link_libraries
(
test_layout PRIVATE utility
)
target_link_libraries
(
test_layout PRIVATE utility
)
add_gtest_executable
(
test_tensor test_tensor.cpp
)
add_gtest_executable
(
test_tensor test_tensor.cpp
)
target_link_libraries
(
test_tensor PRIVATE utility
)
target_link_libraries
(
test_tensor PRIVATE utility
)
add_gtest_executable
(
test_copy test_copy.cpp
)
target_link_libraries
(
test_copy PRIVATE utility
)
add_gtest_executable
(
test_partition test_partition.cpp
)
target_link_libraries
(
test_partition PRIVATE utility
)
test/wrapper/test_copy.cpp
0 → 100644
View file @
71d6ede7
// SPDX-License-Identifier: MIT
// Copyright (c) 2023-2024, Advanced Micro Devices, Inc. All rights reserved.
#include <numeric>
#include <cstdlib>
#include <iostream>
#include <initializer_list>
#include <vector>
#include <gtest/gtest.h>
#include "ck/host_utility/kernel_launch.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/utility/common_header.hpp"
#include "ck/wrapper/layout.hpp"
#include "ck/wrapper/tensor.hpp"
#include "ck/wrapper/operations/copy.hpp"
// Test copy from Global to Global through LDS and VGPR
template
<
typename
InputTensor
,
typename
OutputTensor
,
typename
BlockShape
,
typename
ThreadLayoutShape
,
typename
LocalTileSteps
,
typename
LocalPartitionSteps
>
__global__
void
TestCopyDevice
(
const
InputTensor
input_tensor
,
OutputTensor
output_tensor
,
const
BlockShape
tile_shape
,
const
ThreadLayoutShape
thread_layout
,
const
LocalTileSteps
block_steps
,
const
LocalPartitionSteps
thread_steps
)
{
__shared__
ck
::
index_t
p_shared
[
ck
::
wrapper
::
size
(
tile_shape
)];
auto
tensor_lds
=
ck
::
wrapper
::
make_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Lds
>
(
p_shared
,
ck
::
wrapper
::
make_layout
(
tile_shape
));
const
auto
block_idxs
=
ck
::
make_tuple
(
ck
::
make_tuple
(
0
,
0
),
blockIdx
.
x
);
// Get local tiles for global memory
const
auto
input_local_tile
=
ck
::
wrapper
::
make_local_tile
(
input_tensor
,
tile_shape
,
block_idxs
,
block_steps
);
const
auto
output_local_tile
=
ck
::
wrapper
::
make_local_tile
(
output_tensor
,
tile_shape
,
block_idxs
,
block_steps
);
// Get partition per thread
const
auto
input_local_partition
=
ck
::
wrapper
::
make_local_partition
(
input_local_tile
,
thread_layout
,
threadIdx
.
x
,
thread_steps
);
auto
lds_local_partition
=
ck
::
wrapper
::
make_local_partition
(
tensor_lds
,
thread_layout
,
threadIdx
.
x
,
thread_steps
);
auto
output_local_partition
=
ck
::
wrapper
::
make_local_partition
(
output_local_tile
,
thread_layout
,
threadIdx
.
x
,
thread_steps
);
// Allocate VGPR
constexpr
ck
::
index_t
scalar_per_vector
=
1
;
constexpr
ck
::
index_t
vgpr_size
=
ck
::
wrapper
::
size
(
lds_local_partition
);
auto
tensor_vgpr
=
ck
::
wrapper
::
make_register_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Vgpr
,
vgpr_size
,
scalar_per_vector
,
ck
::
index_t
>
();
// Perform copy
ck
::
wrapper
::
copy
(
input_local_partition
,
lds_local_partition
);
ck
::
wrapper
::
copy
(
lds_local_partition
,
tensor_vgpr
);
ck
::
wrapper
::
copy
(
tensor_vgpr
,
output_local_partition
);
}
void
PerformCopyGlobalToGlobalViaLDS
()
{
const
auto
shape
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
2
>
{},
ck
::
Number
<
2
>
{}),
ck
::
Number
<
256
>
{});
const
auto
strides
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
1
>
{},
ck
::
Number
<
2
>
{}),
ck
::
Number
<
4
>
{});
const
auto
layout
=
ck
::
wrapper
::
make_layout
(
shape
,
strides
);
// 0, 1, 2, ..., size(shape) - 1
std
::
vector
<
ck
::
index_t
>
input_data
(
ck
::
wrapper
::
size
(
shape
));
std
::
iota
(
input_data
.
begin
(),
input_data
.
end
(),
0
);
// Global memory buffers
DeviceMem
in_buf
(
ck
::
wrapper
::
size
(
layout
)
*
sizeof
(
ck
::
index_t
));
DeviceMem
out_buf
(
ck
::
wrapper
::
size
(
layout
)
*
sizeof
(
ck
::
index_t
));
in_buf
.
ToDevice
(
input_data
.
data
());
out_buf
.
SetZero
();
// Create tensors for global memory
const
auto
input_tensor_global
=
ck
::
wrapper
::
make_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Global
>
(
static_cast
<
const
ck
::
index_t
*>
(
in_buf
.
GetDeviceBuffer
()),
layout
);
auto
output_tensor_global
=
ck
::
wrapper
::
make_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Global
>
(
static_cast
<
ck
::
index_t
*>
(
out_buf
.
GetDeviceBuffer
()),
layout
);
const
auto
thread_layout
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
1
>
{},
ck
::
Number
<
1
>
{}),
ck
::
Number
<
32
>
{});
const
auto
tile_shape
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
2
>
{},
ck
::
Number
<
2
>
{}),
ck
::
Number
<
64
>
{});
const
auto
thread_steps
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
1
>
{},
ck
::
Number
<
1
>
{}),
ck
::
Number
<
2
>
{});
const
auto
block_steps
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
1
>
{},
ck
::
Number
<
1
>
{}),
ck
::
Number
<
64
>
{});
const
ck
::
index_t
grid_size
=
ck
::
math
::
integer_divide_ceil
(
ck
::
wrapper
::
size
(
input_tensor_global
),
ck
::
wrapper
::
size
(
tile_shape
));
const
auto
kernel
=
TestCopyDevice
<
decltype
(
input_tensor_global
),
decltype
(
output_tensor_global
),
decltype
(
tile_shape
),
decltype
(
thread_layout
),
decltype
(
block_steps
),
decltype
(
thread_steps
)
>
;
launch_and_time_kernel
(
StreamConfig
{},
kernel
,
dim3
(
grid_size
),
dim3
(
ck
::
wrapper
::
size
(
thread_layout
)),
0
,
input_tensor_global
,
output_tensor_global
,
tile_shape
,
thread_layout
,
block_steps
,
thread_steps
);
// Verify results
std
::
vector
<
ck
::
index_t
>
output_data
(
ck
::
wrapper
::
size
(
shape
));
out_buf
.
FromDevice
(
output_data
.
data
());
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
output_data
,
input_data
));
}
TEST
(
TestCopy
,
CopyGlobalToGlobalViaLDS
)
{
PerformCopyGlobalToGlobalViaLDS
();
}
test/wrapper/test_layout.cpp
View file @
71d6ede7
...
@@ -84,7 +84,8 @@ TEST_F(TestWrapperLayout, 2d)
...
@@ -84,7 +84,8 @@ TEST_F(TestWrapperLayout, 2d)
ck
::
make_tuple
(
ck
::
Sequence
<
0
>
{}));
ck
::
make_tuple
(
ck
::
Sequence
<
0
>
{}));
const
auto
layout_runtime
=
ck
::
wrapper
::
make_layout
(
ck
::
make_tuple
(
d1
,
d0
));
const
auto
layout_runtime
=
ck
::
wrapper
::
make_layout
(
ck
::
make_tuple
(
d1
,
d0
));
const
auto
layout_compiletime
=
const
auto
layout_compiletime
=
ck
::
wrapper
::
make_layout
(
ck
::
make_tuple
(
ck
::
Number
<
d1
>
{},
ck
::
Number
<
d0
>
{}));
ck
::
wrapper
::
make_layout
(
ck
::
make_tuple
(
ck
::
Number
<
d1
>
{},
ck
::
Number
<
d0
>
{}),
ck
::
make_tuple
(
ck
::
Number
<
s1
>
{},
ck
::
Number
<
s0
>
{}));
std
::
vector
<
ck
::
Tuple
<
ck
::
index_t
,
ck
::
index_t
>>
idxs
;
std
::
vector
<
ck
::
Tuple
<
ck
::
index_t
,
ck
::
index_t
>>
idxs
;
for
(
ck
::
index_t
h
=
0
;
h
<
d1
;
h
++
)
for
(
ck
::
index_t
h
=
0
;
h
<
d1
;
h
++
)
...
@@ -435,19 +436,11 @@ TEST(TestLayoutHelpers, ShapeAndStrides)
...
@@ -435,19 +436,11 @@ TEST(TestLayoutHelpers, ShapeAndStrides)
constexpr
bool
check_compiletime_shape
=
constexpr
bool
check_compiletime_shape
=
std
::
is_same_v
<
decltype
(
shape_compiletime
),
std
::
is_same_v
<
decltype
(
shape_compiletime
),
std
::
remove_reference_t
<
decltype
(
shape
(
layout_compiletime
))
>>
;
std
::
remove_reference_t
<
decltype
(
shape
(
layout_compiletime
))
>>
;
constexpr
bool
check_compiletime_strides
=
std
::
is_same_v
<
decltype
(
strides_compiletime
),
std
::
remove_reference_t
<
decltype
(
stride
(
layout_compiletime
))
>>
;
constexpr
bool
check_runtime_shape
=
constexpr
bool
check_runtime_shape
=
std
::
is_same_v
<
decltype
(
shape_runtime
),
std
::
is_same_v
<
decltype
(
shape_runtime
),
std
::
remove_reference_t
<
decltype
(
shape
(
layout_runtime
))
>>
;
std
::
remove_reference_t
<
decltype
(
shape
(
layout_runtime
))
>>
;
constexpr
bool
check_runtime_strides
=
std
::
is_same_v
<
decltype
(
strides_runtime
),
std
::
remove_reference_t
<
decltype
(
stride
(
layout_runtime
))
>>
;
EXPECT_TRUE
(
check_compiletime_shape
);
EXPECT_TRUE
(
check_compiletime_shape
);
EXPECT_TRUE
(
check_compiletime_strides
);
EXPECT_TRUE
(
check_runtime_shape
);
EXPECT_TRUE
(
check_runtime_shape
);
EXPECT_TRUE
(
check_runtime_strides
);
}
}
TEST
(
TestLayoutHelpers
,
Hierarchical
)
TEST
(
TestLayoutHelpers
,
Hierarchical
)
...
...
test/wrapper/test_partition.cpp
0 → 100644
View file @
71d6ede7
// SPDX-License-Identifier: MIT
// Copyright (c) 2023-2024, Advanced Micro Devices, Inc. All rights reserved.
#include <numeric>
#include <cstdlib>
#include <iostream>
#include <initializer_list>
#include <vector>
#include <gtest/gtest.h>
#include "ck/host_utility/kernel_launch.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/utility/common_header.hpp"
#include "ck/wrapper/layout.hpp"
#include "ck/wrapper/tensor.hpp"
TEST
(
TestPartition
,
LocalPartition
)
{
const
auto
shape
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
16
>
{},
ck
::
Number
<
4
>
{}),
ck
::
Number
<
4
>
{});
const
auto
strides
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
1
>
{},
ck
::
Number
<
16
>
{}),
ck
::
Number
<
64
>
{});
const
auto
layout
=
ck
::
wrapper
::
make_layout
(
shape
,
strides
);
std
::
vector
<
ck
::
index_t
>
data
(
ck
::
wrapper
::
size
(
layout
));
std
::
iota
(
data
.
begin
(),
data
.
end
(),
0
);
const
auto
tensor
=
ck
::
wrapper
::
make_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Generic
>
(
data
.
data
(),
layout
);
const
auto
thread_steps
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
2
>
{},
ck
::
Number
<
1
>
{}),
ck
::
Number
<
1
>
{});
const
auto
thread_layout
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
8
>
{},
ck
::
Number
<
1
>
{}),
ck
::
Number
<
1
>
{});
for
(
ck
::
index_t
thread_id
=
0
;
thread_id
<
ck
::
wrapper
::
size
(
thread_layout
);
thread_id
++
)
{
const
auto
raked_partition
=
ck
::
wrapper
::
make_local_partition
(
tensor
,
thread_layout
,
thread_id
);
const
auto
expected_partition_size
=
ck
::
wrapper
::
size
(
tensor
)
/
ck
::
wrapper
::
size
(
thread_layout
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
raked_partition
),
expected_partition_size
);
EXPECT_EQ
(
raked_partition
(
0
),
thread_id
);
}
for
(
ck
::
index_t
thread_id
=
0
;
thread_id
<
ck
::
wrapper
::
size
(
thread_layout
);
thread_id
++
)
{
const
auto
packed_partition
=
ck
::
wrapper
::
make_local_partition
(
tensor
,
thread_layout
,
thread_id
,
thread_steps
);
const
auto
expected_partition_size
=
ck
::
wrapper
::
size
(
tensor
)
/
ck
::
wrapper
::
size
(
thread_layout
);
const
auto
expected_partition_first_val
=
thread_id
*
ck
::
wrapper
::
size
<
0
,
0
>
(
thread_steps
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
packed_partition
),
expected_partition_size
);
EXPECT_EQ
(
packed_partition
(
0
),
expected_partition_first_val
);
}
}
TEST
(
TestPartition
,
LocalTile
)
{
const
auto
shape
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
16
>
{},
ck
::
Number
<
4
>
{}),
ck
::
Number
<
4
>
{});
const
auto
strides
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
1
>
{},
ck
::
Number
<
16
>
{}),
ck
::
Number
<
64
>
{});
const
auto
layout
=
ck
::
wrapper
::
make_layout
(
shape
,
strides
);
std
::
vector
<
ck
::
index_t
>
data
(
ck
::
wrapper
::
size
(
layout
));
std
::
iota
(
data
.
begin
(),
data
.
end
(),
0
);
const
auto
tensor
=
ck
::
wrapper
::
make_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Generic
>
(
data
.
data
(),
layout
);
const
auto
block_steps
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
4
>
{},
ck
::
Number
<
2
>
{}),
ck
::
Number
<
2
>
{});
const
auto
block_shape
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
4
>
{},
ck
::
Number
<
2
>
{}),
ck
::
Number
<
2
>
{});
const
auto
block_layout
=
ck
::
make_tuple
(
ck
::
make_tuple
(
ck
::
Number
<
4
>
{},
ck
::
Number
<
2
>
{}),
ck
::
Number
<
2
>
{});
std
::
vector
<
ck
::
Tuple
<
ck
::
Tuple
<
ck
::
index_t
,
ck
::
index_t
>
,
ck
::
index_t
>>
block_idxs
;
for
(
ck
::
index_t
x
=
0
;
x
<
ck
::
wrapper
::
size
<
0
,
0
>
(
block_layout
);
x
++
)
{
for
(
ck
::
index_t
y
=
0
;
y
<
ck
::
wrapper
::
size
<
0
,
1
>
(
block_layout
);
y
++
)
{
for
(
ck
::
index_t
z
=
0
;
z
<
ck
::
wrapper
::
size
<
1
>
(
block_layout
);
z
++
)
{
block_idxs
.
emplace_back
(
ck
::
make_tuple
(
x
,
y
),
z
);
}
}
}
for
(
const
auto
&
block_idx
:
block_idxs
)
{
const
auto
raked_tile
=
ck
::
wrapper
::
make_local_tile
(
tensor
,
block_shape
,
block_idx
);
const
auto
expected_tile_size
=
ck
::
wrapper
::
size
(
block_shape
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
raked_tile
),
expected_tile_size
);
EXPECT_EQ
(
raked_tile
(
0
),
layout
(
block_idx
));
}
for
(
const
auto
&
block_idx
:
block_idxs
)
{
const
auto
packed_tile
=
ck
::
wrapper
::
make_local_tile
(
tensor
,
block_shape
,
block_idx
,
block_steps
);
const
auto
expected_tile_size
=
ck
::
wrapper
::
size
(
block_shape
);
const
auto
expected_tile_first_val
=
ck
::
wrapper
::
size
<
0
,
0
>
(
block_idx
)
*
ck
::
wrapper
::
size
<
0
,
0
>
(
block_shape
)
*
ck
::
wrapper
::
size
<
0
,
0
>
(
strides
)
+
ck
::
wrapper
::
size
<
0
,
1
>
(
block_idx
)
*
ck
::
wrapper
::
size
<
0
,
1
>
(
block_shape
)
*
ck
::
wrapper
::
size
<
0
,
1
>
(
strides
)
+
ck
::
wrapper
::
size
<
1
>
(
block_idx
)
*
ck
::
wrapper
::
size
<
1
>
(
block_shape
)
*
ck
::
wrapper
::
size
<
1
>
(
strides
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
packed_tile
),
expected_tile_size
);
EXPECT_EQ
(
packed_tile
(
0
),
expected_tile_first_val
);
}
}
test/wrapper/test_tensor.cpp
View file @
71d6ede7
...
@@ -108,7 +108,6 @@ __global__ void TestTensorReadWriteDevice(void* data, void* success)
...
@@ -108,7 +108,6 @@ __global__ void TestTensorReadWriteDevice(void* data, void* success)
bool
*
casted_success_ptr
=
static_cast
<
bool
*>
(
success
);
bool
*
casted_success_ptr
=
static_cast
<
bool
*>
(
success
);
const
auto
layout
=
ck
::
wrapper
::
make_layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
2
,
2
),
2
));
const
auto
layout
=
ck
::
wrapper
::
make_layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
2
,
2
),
2
));
constexpr
auto
register_layout
=
ck
::
wrapper
::
make_layout
(
ck
::
make_tuple
(
ck
::
Number
<
8
>
{}));
auto
tensor_global
=
auto
tensor_global
=
ck
::
wrapper
::
make_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Global
>
(
casted_data_ptr
,
layout
);
ck
::
wrapper
::
make_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Global
>
(
casted_data_ptr
,
layout
);
...
@@ -116,11 +115,11 @@ __global__ void TestTensorReadWriteDevice(void* data, void* success)
...
@@ -116,11 +115,11 @@ __global__ void TestTensorReadWriteDevice(void* data, void* success)
auto
tensor_vgpr
=
ck
::
wrapper
::
make_register_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Vgpr
,
auto
tensor_vgpr
=
ck
::
wrapper
::
make_register_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Vgpr
,
nelems
,
nelems
,
scalar_per_vector
,
scalar_per_vector
,
ck
::
index_t
>
(
register_layout
);
ck
::
index_t
>
();
auto
tensor_sgpr
=
ck
::
wrapper
::
make_register_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Sgpr
,
auto
tensor_sgpr
=
ck
::
wrapper
::
make_register_tensor
<
ck
::
wrapper
::
MemoryTypeEnum
::
Sgpr
,
nelems
,
nelems
,
scalar_per_vector
,
scalar_per_vector
,
ck
::
index_t
>
(
register_layout
);
ck
::
index_t
>
();
InitTensor
(
tensor_global
);
InitTensor
(
tensor_global
);
InitTensor
(
tensor_lds
);
InitTensor
(
tensor_lds
);
...
@@ -151,7 +150,7 @@ TEST(TestTensor, ReadWriteGlobalLdsRegistersMemory)
...
@@ -151,7 +150,7 @@ TEST(TestTensor, ReadWriteGlobalLdsRegistersMemory)
TestTensorReadWriteDevice
,
TestTensorReadWriteDevice
,
dim3
(
1
),
dim3
(
1
),
dim3
(
1
),
dim3
(
1
),
nelems
*
sizeof
(
ck
::
index_t
)
,
0
,
data_buf
.
GetDeviceBuffer
(),
data_buf
.
GetDeviceBuffer
(),
success_buf
.
GetDeviceBuffer
());
success_buf
.
GetDeviceBuffer
());
...
@@ -173,33 +172,45 @@ TEST(TestTensor, Slicing)
...
@@ -173,33 +172,45 @@ TEST(TestTensor, Slicing)
auto
tensor2x2x2
=
auto
tensor2x2x2
=
tensor
(
ck
::
make_tuple
(
ck
::
wrapper
::
slice
(
2
),
ck
::
wrapper
::
slice
(
2
)),
ck
::
wrapper
::
slice
(
2
));
tensor
(
ck
::
make_tuple
(
ck
::
wrapper
::
slice
(
2
),
ck
::
wrapper
::
slice
(
2
)),
ck
::
wrapper
::
slice
(
2
));
EXPECT_EQ
(
tensor2x2x2
(
0
),
layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
0
,
0
),
0
)));
EXPECT_EQ
(
ck
::
wrapper
::
rank
(
tensor2x2x2
),
2
);
EXPECT_EQ
(
ck
::
wrapper
::
rank
(
tensor2x2x2
),
2
);
EXPECT_EQ
(
ck
::
wrapper
::
depth
(
tensor2x2x2
),
2
);
EXPECT_EQ
(
ck
::
wrapper
::
depth
(
tensor2x2x2
),
2
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
tensor2x2x2
),
8
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
tensor2x2x2
),
8
);
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor2x2x2
));
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor2x2x2
));
auto
tensor2x2
=
tensor
(
ck
::
make_tuple
(
1
,
ck
::
wrapper
::
slice
(
2
)),
ck
::
wrapper
::
slice
(
2
));
auto
tensor2x2
=
tensor
(
ck
::
make_tuple
(
1
,
ck
::
wrapper
::
slice
(
2
)),
ck
::
wrapper
::
slice
(
2
));
EXPECT_EQ
(
tensor2x2
(
0
),
layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
1
,
0
),
0
)));
EXPECT_EQ
(
ck
::
wrapper
::
rank
(
tensor2x2
),
2
);
EXPECT_EQ
(
ck
::
wrapper
::
rank
(
tensor2x2
),
2
);
EXPECT_EQ
(
ck
::
wrapper
::
depth
(
tensor2x2
),
2
);
EXPECT_EQ
(
ck
::
wrapper
::
depth
(
tensor2x2
),
2
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
tensor2x2
),
4
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
tensor2x2
),
4
);
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor2x2
,
layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
1
,
0
),
0
))
));
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor2x2
));
auto
tensor1x1
=
tensor
(
ck
::
make_tuple
(
1
,
ck
::
wrapper
::
slice
(
1
,
2
)),
ck
::
wrapper
::
slice
(
1
,
2
));
auto
tensor1x1
=
tensor
(
ck
::
make_tuple
(
1
,
ck
::
wrapper
::
slice
(
1
,
2
)),
ck
::
wrapper
::
slice
(
1
,
2
));
EXPECT_EQ
(
tensor1x1
(
0
),
layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
1
,
1
),
1
)));
EXPECT_EQ
(
rank
(
tensor1x1
),
2
);
EXPECT_EQ
(
rank
(
tensor1x1
),
2
);
EXPECT_EQ
(
depth
(
tensor1x1
),
2
);
EXPECT_EQ
(
depth
(
tensor1x1
),
2
);
EXPECT_EQ
(
size
(
tensor1x1
),
1
);
EXPECT_EQ
(
size
(
tensor1x1
),
1
);
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor1x1
,
layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
1
,
1
),
1
))
));
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor1x1
));
auto
tensor2
=
tensor
(
ck
::
make_tuple
(
1
,
1
),
ck
::
wrapper
::
slice
(
0
,
2
));
auto
tensor2
=
tensor
(
ck
::
make_tuple
(
1
,
1
),
ck
::
wrapper
::
slice
(
0
,
2
));
EXPECT_EQ
(
tensor2
(
0
),
layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
1
,
1
),
0
)));
EXPECT_EQ
(
ck
::
wrapper
::
rank
(
tensor2
),
1
);
EXPECT_EQ
(
ck
::
wrapper
::
rank
(
tensor2
),
1
);
EXPECT_EQ
(
ck
::
wrapper
::
depth
(
tensor2
),
1
);
EXPECT_EQ
(
ck
::
wrapper
::
depth
(
tensor2
),
1
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
tensor2
),
2
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
tensor2
),
2
);
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor2
,
layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
1
,
1
),
0
))));
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor2
));
auto
tensor2_v2
=
tensor
(
2
,
ck
::
wrapper
::
slice
(
0
,
2
));
EXPECT_EQ
(
tensor2_v2
(
0
),
layout
(
ck
::
make_tuple
(
2
,
0
)));
EXPECT_EQ
(
ck
::
wrapper
::
rank
(
tensor2_v2
),
1
);
EXPECT_EQ
(
ck
::
wrapper
::
depth
(
tensor2_v2
),
1
);
EXPECT_EQ
(
ck
::
wrapper
::
size
(
tensor2_v2
),
2
);
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor2_v2
));
// negative indexing
// negative indexing
auto
tensor1x2
=
tensor
(
ck
::
make_tuple
(
1
,
ck
::
wrapper
::
slice
(
0
,
-
2
)),
ck
::
wrapper
::
slice
());
auto
tensor1x2
=
tensor
(
ck
::
make_tuple
(
1
,
ck
::
wrapper
::
slice
(
0
,
-
2
)),
ck
::
wrapper
::
slice
());
EXPECT_EQ
(
tensor1x2
(
0
),
layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
1
,
0
),
0
)));
EXPECT_EQ
(
rank
(
tensor1x2
),
2
);
EXPECT_EQ
(
rank
(
tensor1x2
),
2
);
EXPECT_EQ
(
depth
(
tensor1x2
),
2
);
EXPECT_EQ
(
depth
(
tensor1x2
),
2
);
EXPECT_EQ
(
size
(
tensor1x2
),
2
);
EXPECT_EQ
(
size
(
tensor1x2
),
2
);
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor1x2
,
layout
(
ck
::
make_tuple
(
ck
::
make_tuple
(
1
,
0
),
0
))
));
EXPECT_TRUE
(
TestTensorCheck1d
(
tensor1x2
));
}
}
Prev
1
2
3
Next
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