|
1 | | -// Copyright (c) 2020-2021, NVIDIA CORPORATION. |
| 1 | +// Copyright (c) 2020-2022, NVIDIA CORPORATION. |
2 | 2 | // |
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | // you may not use this file except in compliance with the License. |
@@ -69,6 +69,19 @@ Napi::Value cudaMemGetInfoNapi(CallbackArgs const& args) { |
69 | 69 | std::vector<std::string>{"free", "total"}); |
70 | 70 | } |
71 | 71 |
|
| 72 | +Napi::Value cudaPointerGetAttributesNapi(CallbackArgs const& args) { |
| 73 | + auto env = args.Env(); |
| 74 | + void* dptr = args[0]; |
| 75 | + CUDARTAPI::cudaPointerAttributes attrs{}; |
| 76 | + NODE_CUDA_TRY(CUDARTAPI::cudaPointerGetAttributes(&attrs, dptr), env); |
| 77 | + auto obj = Napi::Object::New(env); |
| 78 | + obj.Set("type", attrs.type); |
| 79 | + obj.Set("device", attrs.device); |
| 80 | + obj.Set("hptr", reinterpret_cast<uint64_t>(attrs.hostPointer)); |
| 81 | + obj.Set("dptr", reinterpret_cast<uint64_t>(attrs.devicePointer)); |
| 82 | + return obj; |
| 83 | +} |
| 84 | + |
72 | 85 | // CUresult cuPointerGetAttribute(void *data, CUpointer_attribute attribute, |
73 | 86 | // CUdeviceptr ptr); |
74 | 87 | Napi::Value cuPointerGetAttributeNapi(CallbackArgs const& args) { |
@@ -140,6 +153,7 @@ Napi::Object initModule(Napi::Env const& env, |
140 | 153 | EXPORT_FUNC(env, runtime, "cudaMemset", cudaMemsetNapi); |
141 | 154 | EXPORT_FUNC(env, runtime, "cudaMemcpy", cudaMemcpyNapi); |
142 | 155 | EXPORT_FUNC(env, runtime, "cudaMemGetInfo", cudaMemGetInfoNapi); |
| 156 | + EXPORT_FUNC(env, runtime, "cudaPointerGetAttributes", cudaPointerGetAttributesNapi); |
143 | 157 | EXPORT_FUNC(env, driver, "cuPointerGetAttribute", cuPointerGetAttributeNapi); |
144 | 158 |
|
145 | 159 | auto PointerAttributes = Napi::Object::New(env); |
|
0 commit comments