forked from NVIDIA/DALI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for GPU based numpy reader (NVIDIA#2477)
- GPU based numpy reader uses GPU Direct Storage via cufile library implementation Authored-by: Thorsten Kurth <[email protected]> Co-authored-by: Michał Zientkiewicz <[email protected]> Co-authored-by: Janusz Lisiecki <[email protected]> Signed-off-by: Janusz Lisiecki <[email protected]>
- Loading branch information
1 parent
647cf31
commit add3a20
Showing
61 changed files
with
1,755 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
DALI_@DALI_VERSION@ { | ||
global: | ||
*; | ||
# cufile.h declares all its symbols with the default visibility so our wrappers | ||
# are exported as well. We don't want this so hide it explicitly here | ||
local: cuFile*; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
DALI_CORE_@DALI_VERSION@ { | ||
global: | ||
*; | ||
# cufile.h declares all its symbols with the default visibility so our wrappers | ||
# are exported as well. We don't want this so hide it explicitly here | ||
local: cuFile*; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
DALI_KERNELS_@DALI_VERSION@ { | ||
global: | ||
*; | ||
# cufile.h declares all its symbols with the default visibility so our wrappers | ||
# are exported as well. We don't want this so hide it explicitly here | ||
local: cuFile*; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
DALI_OPERATORS_@DALI_VERSION@ { | ||
global: | ||
*; | ||
# cufile.h declares all its symbols with the default visibility so our wrappers | ||
# are exported as well. We don't want this so hide it explicitly here | ||
local: cuFile*; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. | ||
// | ||
// 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. | ||
|
||
#include <dlfcn.h> | ||
#include <stdio.h> | ||
#include <mutex> | ||
#include <string> | ||
#include <unordered_map> | ||
#include "dali/core/dynlink_cufile.h" | ||
|
||
namespace { | ||
|
||
typedef void* CUFILE; | ||
|
||
static const char __CufileLibName[] = "libcufile.so"; | ||
static const char __CufileLibName1[] = "libcufile.so.1"; | ||
|
||
CUFILE loadCufileLibrary() { | ||
CUFILE ret = nullptr; | ||
|
||
ret = dlopen(__CufileLibName1, RTLD_NOW); | ||
|
||
if (!ret) { | ||
ret = dlopen(__CufileLibName, RTLD_NOW); | ||
|
||
if (!ret) { | ||
printf("dlopen \"%s\" failed!\n", __CufileLibName); | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
void *LoadSymbol(const char *name) { | ||
static CUFILE cufileDrvLib = loadCufileLibrary(); | ||
void *ret = cufileDrvLib ? dlsym(cufileDrvLib, name) : nullptr; | ||
return ret; | ||
} | ||
|
||
} // namespace | ||
|
||
// it is defined in the generated file | ||
typedef void *tLoadSymbol(const char *name); | ||
void CufileSetSymbolLoader(tLoadSymbol loader_func); | ||
|
||
void cufileInit() { | ||
#if CUFILE_ENABLED | ||
static std::once_flag cufile_once; | ||
std::call_once(cufile_once, CufileSetSymbolLoader, LoadSymbol); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. | ||
// | ||
// 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. | ||
|
||
#include <dirent.h> | ||
#include <errno.h> | ||
#include <glob.h> | ||
#include <memory> | ||
|
||
#include "dali/core/common.h" | ||
#include "dali/operators/reader/loader/cufile_loader.h" | ||
#include "dali/operators/reader/loader/file_loader.h" | ||
#include "dali/operators/reader/loader/utils.h" | ||
#include "dali/util/cufile.h" | ||
#include "dali/util/cufile_helper.h" | ||
|
||
namespace dali { | ||
|
||
CUFileLoader::CUFileLoader(const OpSpec& spec, vector<std::string> images, bool shuffle_after_epoch) | ||
: FileLoader<GPUBackend, ImageFileWrapperGPU, CUFileStream>(spec) { | ||
// set the device first | ||
DeviceGuard g(device_id_); | ||
|
||
// this is needed for the driver singleton | ||
static std::mutex open_driver_mutex; | ||
static std::weak_ptr<cufile::CUFileDriverHandle> driver_handle; | ||
|
||
// load the cufile driver | ||
std::lock_guard<std::mutex> dlock(open_driver_mutex); | ||
if (!(d_ = driver_handle.lock())) { | ||
d_ = std::make_shared<cufile::CUFileDriverHandle>(device_id_); | ||
driver_handle = d_; | ||
} | ||
} | ||
|
||
void CUFileLoader::PrepareEmpty(ImageFileWrapperGPU& image_file) { | ||
PrepareEmptyTensor(image_file.image); | ||
image_file.filename.clear(); | ||
} | ||
|
||
void CUFileLoader::ReadSample(ImageFileWrapperGPU& imfile) { | ||
// set the device first | ||
DeviceGuard g(device_id_); | ||
this->FileLoader<GPUBackend, ImageFileWrapperGPU, CUFileStream>::ReadSample(imfile); | ||
} | ||
|
||
} // namespace dali |
Oops, something went wrong.