-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
266 additions
and
27 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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2024, 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. | ||
*/ | ||
|
||
#include <chrono> | ||
#include <iostream> | ||
|
||
#include <kvikio/batch.hpp> | ||
#include <kvikio/buffer.hpp> | ||
#include <kvikio/defaults.hpp> | ||
#include <kvikio/driver.hpp> | ||
#include <kvikio/error.hpp> | ||
#include <kvikio/file_handle.hpp> | ||
|
||
using namespace std; | ||
|
||
class Timer { | ||
public: | ||
Timer() : start(std::chrono::high_resolution_clock::now()) {} | ||
|
||
~Timer() | ||
{ | ||
auto end = std::chrono::high_resolution_clock::now(); | ||
auto start_ms = | ||
std::chrono::time_point_cast<std::chrono::microseconds>(start).time_since_epoch().count(); | ||
auto end_ms = | ||
std::chrono::time_point_cast<std::chrono::microseconds>(end).time_since_epoch().count(); | ||
|
||
cout << "(" << end_ms - start_ms << " us)" << endl; | ||
} | ||
|
||
private: | ||
std::chrono::time_point<std::chrono::high_resolution_clock> start; | ||
}; | ||
|
||
void check(bool condition) | ||
{ | ||
if (!condition) { | ||
std::cout << "Error" << std::endl; | ||
exit(-1); | ||
} | ||
} | ||
|
||
constexpr int NELEM = 1024; // Number of elements used throughout the test | ||
constexpr int SIZE = NELEM * sizeof(int); // Size of the memory allocations (in bytes) | ||
constexpr int LARGE_SIZE = 8 * SIZE; // LARGE SIZE to test partial submit (in bytes) | ||
|
||
int main() | ||
{ | ||
cout << "KvikIO defaults: " << endl; | ||
if (kvikio::defaults::compat_mode()) { | ||
cout << " Compatibility mode: enabled" << endl; | ||
} else { | ||
kvikio::DriverInitializer manual_init_driver; | ||
cout << " Compatibility mode: disabled" << endl; | ||
kvikio::DriverProperties props; | ||
cout << "DriverProperties: " << endl; | ||
cout << " nvfs version: " << props.get_nvfs_major_version() << "." | ||
<< props.get_nvfs_minor_version() << endl; | ||
cout << " Allow compatibility mode: " << std::boolalpha << props.get_nvfs_allow_compat_mode() | ||
<< endl; | ||
cout << " Pool mode - enabled: " << std::boolalpha << props.get_nvfs_poll_mode() | ||
<< ", threshold: " << props.get_nvfs_poll_thresh_size() << " kb" << endl; | ||
cout << " Max pinned memory: " << props.get_max_pinned_memory_size() << " kb" << endl; | ||
cout << " Max batch IO size: " << props.get_max_batch_io_size() << endl; | ||
} | ||
|
||
std::vector<int> a(SIZE); | ||
std::iota(a.begin(), a.end(), 0); | ||
std::vector<int> b(SIZE); | ||
std::vector<int> c(SIZE); | ||
check(kvikio::is_host_memory(a.data()) == true); | ||
|
||
{ | ||
cout << endl; | ||
Timer timer; | ||
kvikio::FileHandle file1("/tmp/test-file1", "w"); | ||
kvikio::FileHandle file2("/tmp/test-file2", "w"); | ||
std::future<std::size_t> fut1 = file1.pwrite(a.data(), SIZE); | ||
std::future<std::size_t> fut2 = file2.pwrite(a.data(), SIZE); | ||
size_t written = fut1.get() + fut2.get(); | ||
check(written == SIZE * 2); | ||
check(SIZE == file1.nbytes()); | ||
check(SIZE == file2.nbytes()); | ||
cout << "Write: " << written << endl; | ||
} | ||
{ | ||
std::cout << std::endl; | ||
Timer timer; | ||
kvikio::FileHandle file1("/tmp/test-file1", "r"); | ||
kvikio::FileHandle file2("/tmp/test-file2", "r"); | ||
std::future<std::size_t> fut1 = file1.pread(b.data(), SIZE); | ||
std::future<std::size_t> fut2 = file2.pread(c.data(), SIZE); | ||
size_t read = fut1.get() + fut2.get(); | ||
check(read == SIZE * 2); | ||
check(SIZE == file1.nbytes()); | ||
check(SIZE == file2.nbytes()); | ||
for (int i = 0; i < NELEM; ++i) { | ||
check(a[i] == b[i]); | ||
check(a[i] == c[i]); | ||
} | ||
cout << "Parallel POSIX read (" << kvikio::defaults::thread_pool_nthreads() | ||
<< " threads): " << read << endl; | ||
} | ||
} |
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,64 @@ | ||
/* | ||
* Copyright (c) 2024, 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. | ||
*/ | ||
#pragma once | ||
|
||
/** | ||
* In order to support compilation when `cuda.h` isn't available, we | ||
* wrap all use of cuda in a `#ifdef KVIKIO_CUDA_FOUND` guard. | ||
* | ||
* The motivation here is to make KvikIO work in all circumstances so | ||
* that libraries doesn't have to implement there own fallback solutions. | ||
*/ | ||
#ifdef KVIKIO_CUDA_FOUND | ||
#include <cuda.h> | ||
#else | ||
|
||
// If CUDA isn't defined, we define some of the data types here. | ||
// Notice, this doesn't need to be ABI compatible with the CUDA definitions. | ||
|
||
using CUresult = int; | ||
using CUdeviceptr = unsigned long long; | ||
using CUdevice = int; | ||
using CUcontext = void*; | ||
using CUstream = void*; | ||
|
||
#define CUDA_ERROR_STUB_LIBRARY 0 | ||
#define CUDA_SUCCESS 0 | ||
#define CUDA_ERROR_INVALID_VALUE 0 | ||
#define CU_POINTER_ATTRIBUTE_CONTEXT 0 | ||
#define CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL 0 | ||
#define CU_POINTER_ATTRIBUTE_DEVICE_POINTER 0 | ||
#define CU_MEMHOSTREGISTER_PORTABLE 0 | ||
|
||
CUresult cuInit(...); | ||
CUresult cuMemHostAlloc(...); | ||
CUresult cuMemFreeHost(...); | ||
CUresult cuMemcpyHtoD(...); | ||
CUresult cuMemcpyDtoH(...); | ||
CUresult cuPointerGetAttribute(...); | ||
CUresult cuPointerGetAttributes(...); | ||
CUresult cuCtxPushCurrent(...); | ||
CUresult cuCtxPopCurrent(...); | ||
CUresult cuCtxGetCurrent(...); | ||
CUresult cuMemGetAddressRange(...); | ||
CUresult cuGetErrorName(...); | ||
CUresult cuGetErrorString(...); | ||
CUresult cuDeviceGet(...); | ||
CUresult cuDevicePrimaryCtxRetain(...); | ||
CUresult cuDevicePrimaryCtxRelease(...); | ||
CUresult cuStreamSynchronize(...); | ||
|
||
#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
Oops, something went wrong.