Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cucim.kit.cumed plugin with skeleton #129

Merged
merged 4 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ The build command will create the following files:
- `./install/lib/libcucim*`
- `./python/install/lib/_cucim.cpython-*-x86_64-linux-gnu.so`
- `./cpp/plugins/cucim.kit.cuslide/install/lib/cucim.kit.cuslide@*.so`
- `./cpp/plugins/cucim.kit.cumed/install/lib/cucim.kit.cumed@*.so`

And, it will copy the built library files to `python/cucim/src/cucim/clara/` folder:
- `libcucim.so.*`
- `_cucim.cpython-*-x86_64-linux-gnu.so`
- `cucim.kit.cuslide@*.so`
- `cucim.kit.cumed@*.so`


**Building `cucim`(python bindings)**
Expand All @@ -173,14 +175,14 @@ Once it is built, the subsequent build doesn't take much time.

However, if a build option or dependent packages are updated, the build can be failed (due to CMakeCache.txt or existing build files). In that case, you can remove use the following commands to remove CMakeCache.txt or build folder, then build it again.

1) Remove CMakeCache.txt for libcucim, cuslide plugin, and the python wrapper (pybind11).
1) Remove CMakeCache.txt for libcucim, cuslide/cumed plugin, and the python wrapper (pybind11).

```bash
# this command wouldn't remove already downloaded dependency so faster than `clean` subcommand
./run build_local clean_cache
```

2) Remove `build-*` and `install` folder for libcucim, cuslide plugin, and the python wrapper (pybind11).
2) Remove `build-*` and `install` folder for libcucim, cuslide/cumed plugin, and the python wrapper (pybind11).

```bash
# this command is for clean build
Expand Down
1 change: 1 addition & 0 deletions ci/release/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sed_runner 's/release = .*/release = '"'${NEXT_FULL_TAG}'"'/g' docs/source/conf.
sed_runner "s/${CURRENT_LONG_TAG}/${NEXT_FULL_TAG}/g" VERSION
sed_runner "s/${CURRENT_LONG_TAG}/${NEXT_FULL_TAG}/g" python/cucim/VERSION
sed_runner "s/${CURRENT_LONG_TAG}/${NEXT_FULL_TAG}/g" cpp/plugins/cucim.kit.cuslide/VERSION
sed_runner "s/${CURRENT_LONG_TAG}/${NEXT_FULL_TAG}/g" cpp/plugins/cucim.kit.cumed/VERSION
sed_runner "s#\[Version ${CURRENT_LONG_TAG}\](release_notes/v${CURRENT_LONG_TAG}.md)#\[Version ${NEXT_FULL_TAG}\](release_notes/v${NEXT_FULL_TAG}.md)#g" python/cucim/docs/index.md
sed_runner "s/v${CURRENT_LONG_TAG}/v${NEXT_FULL_TAG}/g" python/cucim/docs/getting_started/index.md
sed_runner "s#cucim.kit.cuslide@${CURRENT_LONG_TAG}.so#cucim.kit.cuslide@${NEXT_FULL_TAG}.so#g" python/cucim/docs/getting_started/index.md
Expand Down
14 changes: 8 additions & 6 deletions conda/recipes/libcucim/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ cp -P -r install/bin/* $PREFIX/bin/ || true
cp -P -r install/lib/* $PREFIX/lib/ || true
cp -P -r install/include/* $PREFIX/include/ || true

# Build libcucim.kit.cuslide plugin
./run build_local cuslide ${CUCIM_BUILD_TYPE} ${PREFIX}

mkdir -p $PREFIX/bin $PREFIX/lib $PREFIX/include
cp -P -r cpp/plugins/cucim.kit.cuslide/install/bin/* $PREFIX/bin/ || true
cp -P -r cpp/plugins/cucim.kit.cuslide/install/lib/* $PREFIX/lib/ || true
# Build plugins
for plugin_name in cuslide cumed; do
echo "Building cucim.kit.${plugin_name} ..."
./run build_local ${plugin_name} ${CUCIM_BUILD_TYPE} ${PREFIX}
mkdir -p $PREFIX/bin $PREFIX/lib $PREFIX/include
cp -P -r cpp/plugins/cucim.kit.${plugin_name}/install/bin/* $PREFIX/bin/ || true
cp -P -r cpp/plugins/cucim.kit.${plugin_name}/install/lib/* $PREFIX/lib/ || true
done
4 changes: 4 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ add_library(${CUCIM_PACKAGE_NAME}
include/cucim/macros/defines.h
include/cucim/memory/dlpack.h
include/cucim/memory/memory_manager.h
include/cucim/plugin/image_format.h
include/cucim/plugin/plugin_config.h
include/cucim/util/cuda.h
include/cucim/util/file.h
include/cucim/util/platform.h
Expand Down Expand Up @@ -96,6 +98,8 @@ add_library(${CUCIM_PACKAGE_NAME}
src/logger/logger.cpp
src/logger/timer.cpp
src/memory/memory_manager.cu
src/plugin/image_format.cpp
src/plugin/plugin_config.cpp
src/util/file.cpp
src/util/platform.cpp)

Expand Down
3 changes: 3 additions & 0 deletions cpp/include/cucim/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "cucim/macros/api_header.h"
#include "cucim/cache/cache_type.h"
#include "cucim/cache/image_cache_config.h"
#include "cucim/plugin/plugin_config.h"

#include <string>
#include <string_view>
Expand All @@ -38,6 +39,7 @@ class EXPORT_VISIBLE Config
Config();

cucim::cache::ImageCacheConfig& cache();
cucim::plugin::PluginConfig& plugin();

std::string shm_name() const;
pid_t pid() const;
Expand All @@ -52,6 +54,7 @@ class EXPORT_VISIBLE Config
std::string source_path_;

cucim::cache::ImageCacheConfig cache_;
cucim::plugin::PluginConfig plugin_;
};

} // namespace cucim::config
Expand Down
6 changes: 4 additions & 2 deletions cpp/include/cucim/core/framework.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -63,7 +63,8 @@ struct PluginLoadingDesc

struct Framework
{
void load_plugins(const PluginLoadingDesc& desc = PluginLoadingDesc::get_default());
// TODO: need to update for better plugin support - https://github.com/rapidsai/cucim/issues/134
// void load_plugins(const PluginLoadingDesc& desc = PluginLoadingDesc::get_default());
jakirkham marked this conversation as resolved.
Show resolved Hide resolved
bool(CUCIM_ABI* register_plugin)(const char* client_name, const PluginRegistrationDesc& desc);
void*(CUCIM_ABI* acquire_interface_from_library_with_client)(const char* client_name,
InterfaceDesc desc,
Expand All @@ -74,6 +75,7 @@ struct Framework
T* acquire_interface_from_library(const char* library_path);

// cuCIM-specific methods
void(CUCIM_ABI* load_plugin)(const char* library_path);
const char*(CUCIM_ABI* get_plugin_root)();
void(CUCIM_ABI* set_plugin_root)(const char* path);
};
Expand Down
6 changes: 4 additions & 2 deletions cpp/include/cucim/cuimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "cucim/io/device.h"
#include "cucim/io/format/image_format.h"
#include "cucim/memory/dlpack.h"
#include "cucim/plugin/image_format.h"

#include <array>
#include <set>
Expand Down Expand Up @@ -106,7 +107,7 @@ class EXPORT_VISIBLE CuImage : public std::enable_shared_from_this<CuImage>

operator bool() const
{
return !!image_formats_ && !is_loaded_;
return !!image_format_ && !is_loaded_;
}

static Framework* get_framework();
Expand Down Expand Up @@ -181,9 +182,10 @@ class EXPORT_VISIBLE CuImage : public std::enable_shared_from_this<CuImage>
// Note: config_ should be placed before cache_manager_ (cache_manager_ depends on config_)
static std::unique_ptr<config::Config> config_;
static std::unique_ptr<cache::ImageCacheManager> cache_manager_;
static std::unique_ptr<cucim::plugin::ImageFormat> image_format_plugins_;

mutable Mutex mutex_;
cucim::io::format::IImageFormat* image_formats_ = nullptr;
cucim::io::format::ImageFormatDesc* image_format_ = nullptr;
CuCIMFileHandle file_handle_{};
io::format::ImageMetadataDesc* image_metadata_ = nullptr;
io::format::ImageDataDesc* image_data_ = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion cpp/include/cucim/io/format/image_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ struct ImageCheckerDesc
* Returns true if the given file is valid for the format
* @param file_name
* @param buf
* @param size
* @return
*/
bool(CUCIM_ABI* is_valid)(const char* file_name, const char* buf);
bool(CUCIM_ABI* is_valid)(const char* file_name, const char* buf, size_t size);
};

struct ImageParserDesc
Expand Down
47 changes: 47 additions & 0 deletions cpp/include/cucim/plugin/image_format.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef CUCIM_PLUGIN_IMAGE_FORMAT_H
#define CUCIM_PLUGIN_IMAGE_FORMAT_H

#include "cucim/filesystem/file_path.h"
#include "cucim/io/format/image_format.h"


namespace cucim::plugin
{

class ImageFormat
{
public:
ImageFormat() = default;
~ImageFormat() = default;

bool add_interfaces(const cucim::io::format::IImageFormat* image_formats);
cucim::io::format::ImageFormatDesc* detect_image_format(const filesystem::Path& path);

operator bool() const
{
return !image_formats_.empty();
}

private:
std::vector<cucim::io::format::ImageFormatDesc*> image_formats_;
};

} // namespace cucim::plugin

#endif // CUCIM_PLUGIN_IMAGE_FORMAT_H
44 changes: 44 additions & 0 deletions cpp/include/cucim/plugin/plugin_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef CUCIM_PLUGIN_PLUGIN_CONFIG_H
#define CUCIM_PLUGIN_PLUGIN_CONFIG_H

#include "cucim/core/framework.h"

#include <string>
#include <vector>

namespace cucim::plugin
{

#define XSTR(x) STR(x)
#define STR(x) #x

struct EXPORT_VISIBLE PluginConfig
{
void load_config(const void* json_obj);

std::vector<std::string> plugin_names{ std::string("cucim.kit.cuslide@" XSTR(CUCIM_VERSION) ".so"),
std::string("cucim.kit.cumed@" XSTR(CUCIM_VERSION) ".so") };
};

#undef STR
#undef XSTR

} // namespace cucim::plugin

#endif // CUCIM_PLUGIN_PLUGIN_CONFIG_H
84 changes: 84 additions & 0 deletions cpp/plugins/cucim.kit.cumed/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine : false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace : true
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: false
ColumnLimit: 120
CommentPragmas: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerBinding: false
FixNamespaceComments: true
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentFunctionDeclarationAfterType: false
IndentWidth: 4
SortIncludes: false
IncludeCategories:
- Regex: '[<"](.*\/)?Defines.h[>"]'
Priority: 1
- Regex: '<[[:alnum:]_.]+>'
Priority: 5
- Regex: '<[[:alnum:]_.\/]+>'
Priority: 4
- Regex: '".*"'
Priority: 2
IncludeBlocks: Regroup
Language: Cpp
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyBreakComment: 1
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 1
PenaltyExcessCharacter: 10
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
Standard: Cpp11
ReflowComments: true
TabWidth: 4
UseTab: Never
7 changes: 7 additions & 0 deletions cpp/plugins/cucim.kit.cumed/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
max_line_length = 120
insert_final_newline = true
3 changes: 3 additions & 0 deletions cpp/plugins/cucim.kit.cumed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake-build*
install

8 changes: 8 additions & 0 deletions cpp/plugins/cucim.kit.cumed/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cpp/plugins/cucim.kit.cumed/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cpp/plugins/cucim.kit.cumed/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cpp/plugins/cucim.kit.cumed/.idea/cucim.kit.cumed.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading