variable_interface.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <common/config.h>
  19. #include <datawizard/coherency.h>
  20. #include <datawizard/copy_driver.h>
  21. #include <datawizard/filters.h>
  22. #include <common/hash.h>
  23. #include <starpu_cuda.h>
  24. #include <starpu_opencl.h>
  25. #include <drivers/opencl/driver_opencl.h>
  26. static int copy_ram_to_ram(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED);
  27. #ifdef STARPU_USE_CUDA
  28. static int copy_ram_to_cuda(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED);
  29. static int copy_cuda_to_ram(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED);
  30. static int copy_ram_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, cudaStream_t stream);
  31. static int copy_cuda_to_ram_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, cudaStream_t stream);
  32. static int copy_cuda_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, cudaStream_t stream);
  33. static int copy_cuda_to_cuda(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED);
  34. #endif
  35. #ifdef STARPU_USE_OPENCL
  36. static int copy_ram_to_opencl(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED);
  37. static int copy_opencl_to_ram(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED);
  38. static int copy_opencl_to_opencl(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED);
  39. static int copy_ram_to_opencl_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, void *_event);
  40. static int copy_opencl_to_ram_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, void *_event);
  41. #endif
  42. static const struct starpu_data_copy_methods variable_copy_data_methods_s = {
  43. .ram_to_ram = copy_ram_to_ram,
  44. .ram_to_spu = NULL,
  45. #ifdef STARPU_USE_CUDA
  46. .ram_to_cuda = copy_ram_to_cuda,
  47. .cuda_to_ram = copy_cuda_to_ram,
  48. .cuda_to_cuda = copy_cuda_to_cuda,
  49. .ram_to_cuda_async = copy_ram_to_cuda_async,
  50. .cuda_to_ram_async = copy_cuda_to_ram_async,
  51. .cuda_to_cuda_async = copy_cuda_to_cuda_async,
  52. #endif
  53. #ifdef STARPU_USE_OPENCL
  54. .ram_to_opencl = copy_ram_to_opencl,
  55. .opencl_to_ram = copy_opencl_to_ram,
  56. .opencl_to_opencl = copy_opencl_to_opencl,
  57. .ram_to_opencl_async = copy_ram_to_opencl_async,
  58. .opencl_to_ram_async = copy_opencl_to_ram_async,
  59. #endif
  60. .cuda_to_spu = NULL,
  61. .spu_to_ram = NULL,
  62. .spu_to_cuda = NULL,
  63. .spu_to_spu = NULL
  64. };
  65. static void register_variable_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface);
  66. static ssize_t allocate_variable_buffer_on_node(void *data_interface_, uint32_t dst_node);
  67. static void *variable_handle_to_pointer(starpu_data_handle data_handle, uint32_t node);
  68. static void free_variable_buffer_on_node(void *data_interface, uint32_t node);
  69. static size_t variable_interface_get_size(starpu_data_handle handle);
  70. static uint32_t footprint_variable_interface_crc32(starpu_data_handle handle);
  71. static int variable_compare(void *data_interface_a, void *data_interface_b);
  72. static void display_variable_interface(starpu_data_handle handle, FILE *f);
  73. #ifdef STARPU_USE_GORDON
  74. static int convert_variable_to_gordon(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss);
  75. #endif
  76. static struct starpu_data_interface_ops_t interface_variable_ops = {
  77. .register_data_handle = register_variable_handle,
  78. .allocate_data_on_node = allocate_variable_buffer_on_node,
  79. .handle_to_pointer = variable_handle_to_pointer,
  80. .free_data_on_node = free_variable_buffer_on_node,
  81. .copy_methods = &variable_copy_data_methods_s,
  82. .get_size = variable_interface_get_size,
  83. .footprint = footprint_variable_interface_crc32,
  84. .compare = variable_compare,
  85. #ifdef STARPU_USE_GORDON
  86. .convert_to_gordon = convert_variable_to_gordon,
  87. #endif
  88. .interfaceid = STARPU_VARIABLE_INTERFACE_ID,
  89. .interface_size = sizeof(starpu_variable_interface_t),
  90. .display = display_variable_interface
  91. };
  92. static void *variable_handle_to_pointer(starpu_data_handle handle, uint32_t node)
  93. {
  94. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  95. return (void*) STARPU_VARIABLE_GET_PTR(starpu_data_get_interface_on_node(handle, node));
  96. }
  97. static void register_variable_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface)
  98. {
  99. unsigned node;
  100. for (node = 0; node < STARPU_MAXNODES; node++)
  101. {
  102. starpu_variable_interface_t *local_interface =
  103. starpu_data_get_interface_on_node(handle, node);
  104. if (node == home_node) {
  105. local_interface->ptr = STARPU_VARIABLE_GET_PTR(data_interface);
  106. }
  107. else {
  108. local_interface->ptr = 0;
  109. }
  110. local_interface->elemsize = STARPU_VARIABLE_GET_ELEMSIZE(data_interface);
  111. }
  112. }
  113. #ifdef STARPU_USE_GORDON
  114. int convert_variable_to_gordon(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss)
  115. {
  116. *ptr = STARPU_VARIABLE_GET_PTR(interface);
  117. (*ss).size = STARPU_VARIABLE_GET_ELEMSIZE(interface);
  118. return 0;
  119. }
  120. #endif
  121. /* declare a new data with the variable interface */
  122. void starpu_variable_data_register(starpu_data_handle *handleptr, uint32_t home_node,
  123. uintptr_t ptr, size_t elemsize)
  124. {
  125. starpu_variable_interface_t variable = {
  126. .ptr = ptr,
  127. .elemsize = elemsize
  128. };
  129. starpu_data_register(handleptr, home_node, &variable, &interface_variable_ops);
  130. }
  131. static uint32_t footprint_variable_interface_crc32(starpu_data_handle handle)
  132. {
  133. return _starpu_crc32_be(starpu_variable_get_elemsize(handle), 0);
  134. }
  135. static int variable_compare(void *data_interface_a, void *data_interface_b)
  136. {
  137. starpu_variable_interface_t *variable_a = data_interface_a;
  138. starpu_variable_interface_t *variable_b = data_interface_b;
  139. /* Two variables are considered compatible if they have the same size */
  140. return (variable_a->elemsize == variable_b->elemsize);
  141. }
  142. static void display_variable_interface(starpu_data_handle handle, FILE *f)
  143. {
  144. starpu_variable_interface_t *variable_interface =
  145. starpu_data_get_interface_on_node(handle, 0);
  146. fprintf(f, "%ld\t", (long)variable_interface->elemsize);
  147. }
  148. static size_t variable_interface_get_size(starpu_data_handle handle)
  149. {
  150. starpu_variable_interface_t *variable_interface =
  151. starpu_data_get_interface_on_node(handle, 0);
  152. return variable_interface->elemsize;
  153. }
  154. uintptr_t starpu_variable_get_local_ptr(starpu_data_handle handle)
  155. {
  156. unsigned node;
  157. node = _starpu_get_local_memory_node();
  158. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  159. return STARPU_VARIABLE_GET_PTR(starpu_data_get_interface_on_node(handle, node));
  160. }
  161. size_t starpu_variable_get_elemsize(starpu_data_handle handle)
  162. {
  163. return STARPU_VARIABLE_GET_ELEMSIZE(starpu_data_get_interface_on_node(handle, 0));
  164. }
  165. /* memory allocation/deallocation primitives for the variable interface */
  166. /* returns the size of the allocated area */
  167. static ssize_t allocate_variable_buffer_on_node(void *data_interface_, uint32_t dst_node)
  168. {
  169. starpu_variable_interface_t *variable_interface = data_interface_;
  170. unsigned fail = 0;
  171. uintptr_t addr = 0;
  172. ssize_t allocated_memory;
  173. size_t elemsize = variable_interface->elemsize;
  174. starpu_node_kind kind = _starpu_get_node_kind(dst_node);
  175. #ifdef STARPU_USE_CUDA
  176. cudaError_t status;
  177. #endif
  178. switch(kind) {
  179. case STARPU_CPU_RAM:
  180. addr = (uintptr_t)malloc(elemsize);
  181. if (!addr)
  182. fail = 1;
  183. break;
  184. #ifdef STARPU_USE_CUDA
  185. case STARPU_CUDA_RAM:
  186. status = cudaMalloc((void **)&addr, elemsize);
  187. if (!addr || (status != cudaSuccess))
  188. {
  189. if (STARPU_UNLIKELY(status != cudaErrorMemoryAllocation))
  190. STARPU_CUDA_REPORT_ERROR(status);
  191. fail = 1;
  192. }
  193. break;
  194. #endif
  195. #ifdef STARPU_USE_OPENCL
  196. case STARPU_OPENCL_RAM:
  197. {
  198. int ret;
  199. void *ptr;
  200. ret = _starpu_opencl_allocate_memory(&ptr, elemsize, CL_MEM_READ_WRITE);
  201. addr = (uintptr_t)ptr;
  202. if (ret) {
  203. fail = 1;
  204. }
  205. break;
  206. }
  207. #endif
  208. default:
  209. assert(0);
  210. }
  211. if (fail)
  212. return -ENOMEM;
  213. /* allocation succeeded */
  214. allocated_memory = elemsize;
  215. /* update the data properly in consequence */
  216. variable_interface->ptr = addr;
  217. return allocated_memory;
  218. }
  219. static void free_variable_buffer_on_node(void *data_interface, uint32_t node)
  220. {
  221. starpu_node_kind kind = _starpu_get_node_kind(node);
  222. switch(kind) {
  223. case STARPU_CPU_RAM:
  224. free((void*)STARPU_VARIABLE_GET_PTR(data_interface));
  225. break;
  226. #ifdef STARPU_USE_CUDA
  227. case STARPU_CUDA_RAM:
  228. cudaFree((void*)STARPU_VARIABLE_GET_PTR(data_interface));
  229. break;
  230. #endif
  231. #ifdef STARPU_USE_OPENCL
  232. case STARPU_OPENCL_RAM:
  233. clReleaseMemObject((void*)STARPU_VARIABLE_GET_PTR(data_interface));
  234. break;
  235. #endif
  236. default:
  237. assert(0);
  238. }
  239. }
  240. #ifdef STARPU_USE_CUDA
  241. static int copy_cuda_common(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  242. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, enum cudaMemcpyKind kind)
  243. {
  244. starpu_variable_interface_t *src_variable = src_interface;
  245. starpu_variable_interface_t *dst_variable = dst_interface;
  246. cudaError_t cures;
  247. cures = cudaMemcpy((char *)dst_variable->ptr, (char *)src_variable->ptr, src_variable->elemsize, kind);
  248. if (STARPU_UNLIKELY(cures))
  249. STARPU_CUDA_REPORT_ERROR(cures);
  250. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_variable->elemsize);
  251. return 0;
  252. }
  253. static int copy_cuda_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  254. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  255. {
  256. return copy_cuda_common(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToHost);
  257. }
  258. static int copy_ram_to_cuda(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  259. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  260. {
  261. return copy_cuda_common(src_interface, src_node, dst_interface, dst_node, cudaMemcpyHostToDevice);
  262. }
  263. static int copy_cuda_to_cuda(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  264. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  265. {
  266. if (src_node == dst_node)
  267. {
  268. return copy_cuda_common(src_interface, src_node, dst_interface, dst_node, cudaMemcpyDeviceToDevice);
  269. }
  270. else {
  271. #ifdef HAVE_CUDA_MEMCPY_PEER
  272. int src_dev = starpu_memory_node_to_devid(src_node);
  273. int dst_dev = starpu_memory_node_to_devid(dst_node);
  274. starpu_variable_interface_t *src_variable = src_interface;
  275. starpu_variable_interface_t *dst_variable = dst_interface;
  276. cudaError_t cures;
  277. cures = cudaMemcpyPeer((char *)dst_variable->ptr, dst_dev, (char *)src_variable->ptr, src_dev, src_variable->elemsize);
  278. if (STARPU_UNLIKELY(cures))
  279. STARPU_CUDA_REPORT_ERROR(cures);
  280. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_variable->elemsize);
  281. #else
  282. /* This is illegal without support for cudaMemcpyPeer */
  283. STARPU_ABORT();
  284. #endif
  285. return 0;
  286. }
  287. }
  288. static int copy_cuda_async_common(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  289. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED,
  290. cudaStream_t stream, enum cudaMemcpyKind kind)
  291. {
  292. starpu_variable_interface_t *src_variable = src_interface;
  293. starpu_variable_interface_t *dst_variable = dst_interface;
  294. cudaError_t cures;
  295. cures = cudaMemcpyAsync((char *)dst_variable->ptr, (char *)src_variable->ptr, src_variable->elemsize, kind, stream);
  296. if (cures)
  297. {
  298. /* do it in a synchronous fashion */
  299. cures = cudaMemcpy((char *)dst_variable->ptr, (char *)src_variable->ptr, src_variable->elemsize, kind);
  300. if (STARPU_UNLIKELY(cures))
  301. STARPU_CUDA_REPORT_ERROR(cures);
  302. return 0;
  303. }
  304. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_variable->elemsize);
  305. return -EAGAIN;
  306. }
  307. static int copy_cuda_to_ram_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  308. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, cudaStream_t stream)
  309. {
  310. return copy_cuda_async_common(src_interface, src_node, dst_interface, dst_node, stream, cudaMemcpyDeviceToHost);
  311. }
  312. static int copy_ram_to_cuda_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  313. void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, cudaStream_t stream)
  314. {
  315. return copy_cuda_async_common(src_interface, src_node, dst_interface, dst_node, stream, cudaMemcpyHostToDevice);
  316. }
  317. static int copy_cuda_to_cuda_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)
  318. {
  319. if (src_node == dst_node)
  320. {
  321. return copy_cuda_async_common(src_interface, src_node, dst_interface, dst_node, stream, cudaMemcpyDeviceToDevice);
  322. }
  323. else {
  324. #ifdef HAVE_CUDA_MEMCPY_PEER
  325. int src_dev = starpu_memory_node_to_devid(src_node);
  326. int dst_dev = starpu_memory_node_to_devid(dst_node);
  327. starpu_variable_interface_t *src_variable = src_interface;
  328. starpu_variable_interface_t *dst_variable = dst_interface;
  329. size_t length = src_variable->elemsize;
  330. cudaError_t cures;
  331. cures = cudaMemcpyPeerAsync((char *)dst_variable->ptr, dst_dev, (char *)src_variable->ptr, src_dev, length, stream);
  332. if (cures)
  333. {
  334. /* sychronous fallback */
  335. cures = cudaMemcpyPeer((char *)dst_variable->ptr, dst_dev, (char *)src_variable->ptr, src_dev, length);
  336. if (STARPU_UNLIKELY(cures))
  337. STARPU_CUDA_REPORT_ERROR(cures);
  338. return 0;
  339. }
  340. STARPU_TRACE_DATA_COPY(src_node, dst_node, length);
  341. return -EAGAIN;
  342. #else
  343. /* This is illegal without cudaMemcpyPeer */
  344. STARPU_ABORT();
  345. return 0;
  346. #endif
  347. }
  348. }
  349. #endif // STARPU_USE_CUDA
  350. #ifdef STARPU_USE_OPENCL
  351. static int copy_ram_to_opencl_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface,
  352. unsigned dst_node STARPU_ATTRIBUTE_UNUSED, void *_event)
  353. {
  354. starpu_variable_interface_t *src_variable = src_interface;
  355. starpu_variable_interface_t *dst_variable = dst_interface;
  356. int err,ret;
  357. err = _starpu_opencl_copy_ram_to_opencl_async_sync((void*)src_variable->ptr, (cl_mem)dst_variable->ptr, src_variable->elemsize,
  358. 0, (cl_event*)_event, &ret);
  359. if (STARPU_UNLIKELY(err))
  360. STARPU_OPENCL_REPORT_ERROR(err);
  361. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_variable->elemsize);
  362. return ret;
  363. }
  364. static int copy_opencl_to_ram_async(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, void *_event)
  365. {
  366. starpu_variable_interface_t *src_variable = src_interface;
  367. starpu_variable_interface_t *dst_variable = dst_interface;
  368. int err, ret;
  369. err = _starpu_opencl_copy_opencl_to_ram_async_sync((cl_mem)src_variable->ptr, (void*)dst_variable->ptr, src_variable->elemsize,
  370. 0, (cl_event*)_event, &ret);
  371. if (STARPU_UNLIKELY(err))
  372. STARPU_OPENCL_REPORT_ERROR(err);
  373. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_variable->elemsize);
  374. return ret;
  375. }
  376. static int copy_ram_to_opencl(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  377. {
  378. return copy_ram_to_opencl_async(src_interface, src_node, dst_interface, dst_node, NULL);
  379. }
  380. static int copy_opencl_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  381. {
  382. return copy_opencl_to_ram_async(src_interface, src_node, dst_interface, dst_node, NULL);
  383. }
  384. static int copy_opencl_to_opencl(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  385. {
  386. cl_int err;
  387. starpu_variable_interface_t *src_variable = src_interface;
  388. starpu_variable_interface_t *dst_variable = dst_interface;
  389. cl_mem src_ptr = (cl_mem)src_variable->ptr;
  390. cl_mem dst_ptr = (cl_mem)dst_variable->ptr;
  391. cl_command_queue cq;
  392. starpu_opencl_get_current_queue(&cq);
  393. STARPU_ASSERT(src_variable->elemsize == dst_variable->elemsize);
  394. err= clEnqueueCopyBuffer(cq, src_ptr, dst_ptr, 0, 0, src_variable->elemsize, 0, NULL, NULL);
  395. if (STARPU_UNLIKELY(err))
  396. STARPU_OPENCL_REPORT_ERROR(err);
  397. STARPU_TRACE_DATA_COPY(src_node, dst_node, src_variable->elemsize);
  398. return 0;
  399. }
  400. #endif
  401. static int copy_ram_to_ram(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  402. {
  403. starpu_variable_interface_t *src_variable = src_interface;
  404. starpu_variable_interface_t *dst_variable = dst_interface;
  405. size_t elemsize = dst_variable->elemsize;
  406. uintptr_t ptr_src = src_variable->ptr;
  407. uintptr_t ptr_dst = dst_variable->ptr;
  408. memcpy((void *)ptr_dst, (void *)ptr_src, elemsize);
  409. STARPU_TRACE_DATA_COPY(src_node, dst_node, elemsize);
  410. return 0;
  411. }