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
Commits
36674bdc
Commit
36674bdc
authored
Oct 10, 2023
by
Alan Turner
Browse files
Changes to embed.cmake
parent
761899c2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
19 deletions
+82
-19
cmake/Embed.cmake
cmake/Embed.cmake
+79
-17
library/src/jit_library/include/ck/host/common.hpp
library/src/jit_library/include/ck/host/common.hpp
+2
-1
library/src/jit_library/src/common.cpp
library/src/jit_library/src/common.cpp
+1
-1
No files found.
cmake/Embed.cmake
View file @
36674bdc
...
@@ -24,6 +24,36 @@
...
@@ -24,6 +24,36 @@
find_program
(
EMBED_LD ld
)
find_program
(
EMBED_LD ld
)
find_program
(
EMBED_OBJCOPY objcopy
)
find_program
(
EMBED_OBJCOPY objcopy
)
option
(
EMBED_USE_LD
"Use ld to embed data files"
ON
)
function
(
wrap_string
)
set
(
options
)
set
(
oneValueArgs VARIABLE AT_COLUMN
)
set
(
multiValueArgs
)
cmake_parse_arguments
(
PARSE
"
${
options
}
"
"
${
oneValueArgs
}
"
"
${
multiValueArgs
}
"
${
ARGN
}
)
cmake_parse_arguments
(
WRAP_STRING
"
${
options
}
"
"
${
oneValueArgs
}
"
""
${
ARGN
}
)
string
(
LENGTH
${${
PARSE_VARIABLE
}}
string_length
)
math
(
EXPR offset
"0"
)
while
(
string_length GREATER 0
)
if
(
string_length GREATER
${
PARSE_AT_COLUMN
}
)
math
(
EXPR length
"
${
PARSE_AT_COLUMN
}
"
)
else
()
math
(
EXPR length
"
${
string_length
}
"
)
endif
()
string
(
SUBSTRING
${${
PARSE_VARIABLE
}}
${
offset
}
${
length
}
line
)
set
(
lines
"
${
lines
}
\n
${
line
}
"
)
math
(
EXPR string_length
"
${
string_length
}
-
${
length
}
"
)
math
(
EXPR offset
"
${
offset
}
+
${
length
}
"
)
endwhile
()
set
(
${
PARSE_VARIABLE
}
"
${
lines
}
"
PARENT_SCOPE
)
endfunction
()
function
(
generate_embed_source EMBED_NAME
)
function
(
generate_embed_source EMBED_NAME
)
set
(
options
)
set
(
options
)
set
(
oneValueArgs SRC HEADER RELATIVE
)
set
(
oneValueArgs SRC HEADER RELATIVE
)
...
@@ -47,14 +77,25 @@ function(generate_embed_source EMBED_NAME)
...
@@ -47,14 +77,25 @@ function(generate_embed_source EMBED_NAME)
list
(
GET PARSE_FILES
${
idx
}
FILE
)
list
(
GET PARSE_FILES
${
idx
}
FILE
)
set
(
START_SYMBOL
"_binary_
${
SYMBOL
}
_start"
)
set
(
START_SYMBOL
"_binary_
${
SYMBOL
}
_start"
)
set
(
END_SYMBOL
"_binary_
${
SYMBOL
}
_length"
)
set
(
LENGTH_SYMBOL
"_binary_
${
SYMBOL
}
_length"
)
string
(
APPEND EXTERNS
"
if
(
EMBED_USE_LD
)
extern const char
${
START_SYMBOL
}
[];
string
(
APPEND EXTERNS
"
extern const char
${
LENGTH_SYMBOL
}
;
extern const char
${
START_SYMBOL
}
[];
"
)
extern const size_t _binary_
${
SYMBOL
}
_size;
const auto
${
LENGTH_SYMBOL
}
= reinterpret_cast<size_t>(&_binary_
${
SYMBOL
}
_size);
"
)
else
()
string
(
APPEND EXTERNS
"
extern const char
${
START_SYMBOL
}
[];
extern const size_t
${
LENGTH_SYMBOL
}
;
"
)
endif
()
file
(
RELATIVE_PATH BASE_NAME
${
PARSE_RELATIVE
}
"
${
FILE
}
"
)
if
(
PARSE_RELATIVE
)
file
(
RELATIVE_PATH BASE_NAME
${
PARSE_RELATIVE
}
"
${
FILE
}
"
)
else
()
get_filename_component
(
BASE_NAME
"
${
FILE
}
"
NAME
)
endif
()
string
(
APPEND INIT_KERNELS
"
string
(
APPEND INIT_KERNELS
"
{
\"
${
BASE_NAME
}
\"
, {
${
START_SYMBOL
}
,
${
LENGTH_SYMBOL
}
} },"
)
{
\"
${
BASE_NAME
}
\"
, {
${
START_SYMBOL
}
,
${
LENGTH_SYMBOL
}
} },"
)
...
@@ -64,7 +105,7 @@ function(generate_embed_source EMBED_NAME)
...
@@ -64,7 +105,7 @@ function(generate_embed_source EMBED_NAME)
#include <string_view>
#include <string_view>
#include <unordered_map>
#include <unordered_map>
#include <utility>
#include <utility>
const
std::unordered_map<std::string_view, std::string_view>
${
EMBED_NAME
}
();
std::unordered_map<std::string_view, std::string_view>
${
EMBED_NAME
}
();
"
)
"
)
file
(
WRITE
"
${
PARSE_SRC
}
"
"
file
(
WRITE
"
${
PARSE_SRC
}
"
"
...
@@ -86,17 +127,38 @@ function(embed_file OUTPUT_FILE OUTPUT_SYMBOL FILE)
...
@@ -86,17 +127,38 @@ function(embed_file OUTPUT_FILE OUTPUT_SYMBOL FILE)
string
(
MAKE_C_IDENTIFIER
"
${
REL_FILE
}
"
SYMBOL
)
string
(
MAKE_C_IDENTIFIER
"
${
REL_FILE
}
"
SYMBOL
)
get_filename_component
(
OUTPUT_FILE_DIR
"
${
REL_FILE
}
"
DIRECTORY
)
get_filename_component
(
OUTPUT_FILE_DIR
"
${
REL_FILE
}
"
DIRECTORY
)
file
(
MAKE_DIRECTORY
"
${
CMAKE_CURRENT_BINARY_DIR
}
/
${
OUTPUT_FILE_DIR
}
"
)
file
(
MAKE_DIRECTORY
"
${
CMAKE_CURRENT_BINARY_DIR
}
/
${
OUTPUT_FILE_DIR
}
"
)
set
(
OUT_FILE
"
${
CMAKE_CURRENT_BINARY_DIR
}
/
${
REL_FILE
}
.o"
)
#use cpp?
if
(
EMBED_USE_LD
)
set
(
OUT_FILE
"
${
CMAKE_CURRENT_BINARY_DIR
}
/
${
REL_FILE
}
.o"
)
else
()
set
(
OUT_FILE
"
${
CMAKE_CURRENT_BINARY_DIR
}
/
${
REL_FILE
}
.cpp"
)
endif
()
set
(
${
OUTPUT_SYMBOL
}
${
SYMBOL
}
PARENT_SCOPE
)
set
(
${
OUTPUT_SYMBOL
}
${
SYMBOL
}
PARENT_SCOPE
)
set
(
${
OUTPUT_FILE
}
"
${
OUT_FILE
}
"
PARENT_SCOPE
)
set
(
${
OUTPUT_FILE
}
"
${
OUT_FILE
}
"
PARENT_SCOPE
)
add_custom_command
(
if
(
EMBED_USE_LD
)
OUTPUT
"
${
OUT_FILE
}
"
add_custom_command
(
COMMAND
${
EMBED_LD
}
-r -o
"
${
OUT_FILE
}
"
-z noexecstack --format=binary
"
${
REL_FILE
}
"
OUTPUT
"
${
OUT_FILE
}
"
COMMAND
${
EMBED_OBJCOPY
}
--rename-section .data=.rodata,alloc,load,readonly,data,contents
"
${
OUT_FILE
}
"
COMMAND
${
EMBED_LD
}
-r -o
"
${
OUT_FILE
}
"
-z noexecstack --format=binary
"
${
REL_FILE
}
"
WORKING_DIRECTORY
${
WORKING_DIRECTORY
}
COMMAND
${
EMBED_OBJCOPY
}
--rename-section .data=.rodata,alloc,load,readonly,data,contents
"
${
OUT_FILE
}
"
DEPENDS
${
FILE
}
WORKING_DIRECTORY
${
WORKING_DIRECTORY
}
VERBATIM
DEPENDS
${
FILE
}
)
VERBATIM
)
else
()
set_property
(
DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
${
FILE
}
)
# reads source file contents as hex string
file
(
READ
${
FILE
}
HEX_STRING HEX
)
# wraps the hex string into multiple lines
wrap_string
(
VARIABLE HEX_STRING AT_COLUMN 80
)
# adds '0x' prefix and comma suffix before and after every byte respectively
string
(
REGEX REPLACE
"([0-9a-f][0-9a-f])"
"0x
\\
1, "
ARRAY_VALUES
${
HEX_STRING
}
)
# removes trailing comma
string
(
REGEX REPLACE
", $"
""
ARRAY_VALUES
${
ARRAY_VALUES
}
)
file
(
WRITE
"
${
OUT_FILE
}
"
"
#include <cstddef>
extern const char _binary_
${
SYMBOL
}
_start[] = {
${
ARRAY_VALUES
}
};
extern const size_t _binary_
${
SYMBOL
}
_length = sizeof(_binary_
${
SYMBOL
}
_start);
"
)
endif
()
endforeach
()
endforeach
()
endfunction
()
endfunction
()
...
...
library/src/jit_library/include/ck/host/common.hpp
View file @
36674bdc
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#pragma once
#pragma once
#include <string>
#include <string>
#include <string_view>
#include <utility>
#include <utility>
#include <unordered_map>
#include <unordered_map>
...
@@ -27,7 +28,7 @@ enum class DataType
...
@@ -27,7 +28,7 @@ enum class DataType
std
::
string
ToString
(
DataType
dt
);
std
::
string
ToString
(
DataType
dt
);
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
const
char
*
,
const
char
*>
>
GetHeaders
();
std
::
unordered_map
<
std
::
string
_view
,
std
::
string_view
>
GetHeaders
();
std
::
size_t
integer_divide_ceil
(
std
::
size_t
x
,
std
::
size_t
y
);
std
::
size_t
integer_divide_ceil
(
std
::
size_t
x
,
std
::
size_t
y
);
...
...
library/src/jit_library/src/common.cpp
View file @
36674bdc
...
@@ -18,7 +18,7 @@ std::string ToString(DataType dt)
...
@@ -18,7 +18,7 @@ std::string ToString(DataType dt)
throw
std
::
runtime_error
(
"Incorrect data type"
);
throw
std
::
runtime_error
(
"Incorrect data type"
);
}
}
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
const
char
*
,
const
char
*>
>
GetHeaders
()
std
::
unordered_map
<
std
::
string
_view
,
std
::
string_view
>
GetHeaders
()
{
{
return
ck_headers
();
return
ck_headers
();
}
}
...
...
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