Timothy Cronin commited on
Commit
6469bfe
·
unverified ·
1 Parent(s): b5e360f

ggml : remove ggml_cpy_inplace and ggml_cont_inplace (ggml/693)

Browse files
Files changed (2) hide show
  1. ggml.c +8 -22
  2. ggml.h +0 -11
ggml.c CHANGED
@@ -4311,13 +4311,13 @@ struct ggml_tensor * ggml_set_2d_inplace(
4311
  static struct ggml_tensor * ggml_cpy_impl(
4312
  struct ggml_context * ctx,
4313
  struct ggml_tensor * a,
4314
- struct ggml_tensor * b,
4315
- bool inplace) {
4316
  GGML_ASSERT(ggml_nelements(a) == ggml_nelements(b));
4317
 
4318
  bool is_node = false;
4319
 
4320
- if (!inplace && (a->grad || b->grad)) {
 
4321
  is_node = true;
4322
  }
4323
 
@@ -4341,29 +4341,21 @@ struct ggml_tensor * ggml_cpy(
4341
  struct ggml_context * ctx,
4342
  struct ggml_tensor * a,
4343
  struct ggml_tensor * b) {
4344
- return ggml_cpy_impl(ctx, a, b, false);
4345
- }
4346
-
4347
- struct ggml_tensor * ggml_cpy_inplace(
4348
- struct ggml_context * ctx,
4349
- struct ggml_tensor * a,
4350
- struct ggml_tensor * b) {
4351
- return ggml_cpy_impl(ctx, a, b, true);
4352
  }
4353
 
4354
  // ggml_cont
4355
 
4356
  static struct ggml_tensor * ggml_cont_impl(
4357
  struct ggml_context * ctx,
4358
- struct ggml_tensor * a,
4359
- bool inplace) {
4360
  bool is_node = false;
4361
 
4362
- if (!inplace && a->grad) {
4363
  is_node = true;
4364
  }
4365
 
4366
- struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a);
4367
  ggml_format_name(result, "%s (cont)", a->name);
4368
 
4369
  result->op = GGML_OP_CONT;
@@ -4376,13 +4368,7 @@ static struct ggml_tensor * ggml_cont_impl(
4376
  struct ggml_tensor * ggml_cont(
4377
  struct ggml_context * ctx,
4378
  struct ggml_tensor * a) {
4379
- return ggml_cont_impl(ctx, a, false);
4380
- }
4381
-
4382
- struct ggml_tensor * ggml_cont_inplace(
4383
- struct ggml_context * ctx,
4384
- struct ggml_tensor * a) {
4385
- return ggml_cont_impl(ctx, a, true);
4386
  }
4387
 
4388
  // make contiguous, with new shape
 
4311
  static struct ggml_tensor * ggml_cpy_impl(
4312
  struct ggml_context * ctx,
4313
  struct ggml_tensor * a,
4314
+ struct ggml_tensor * b) {
 
4315
  GGML_ASSERT(ggml_nelements(a) == ggml_nelements(b));
4316
 
4317
  bool is_node = false;
4318
 
4319
+ if (a->grad || b->grad) {
4320
+ // inplace is false and either one have a grad
4321
  is_node = true;
4322
  }
4323
 
 
4341
  struct ggml_context * ctx,
4342
  struct ggml_tensor * a,
4343
  struct ggml_tensor * b) {
4344
+ return ggml_cpy_impl(ctx, a, b);
 
 
 
 
 
 
 
4345
  }
4346
 
4347
  // ggml_cont
4348
 
4349
  static struct ggml_tensor * ggml_cont_impl(
4350
  struct ggml_context * ctx,
4351
+ struct ggml_tensor * a) {
 
4352
  bool is_node = false;
4353
 
4354
+ if (a->grad) {
4355
  is_node = true;
4356
  }
4357
 
4358
+ struct ggml_tensor * result = ggml_dup_tensor(ctx, a);
4359
  ggml_format_name(result, "%s (cont)", a->name);
4360
 
4361
  result->op = GGML_OP_CONT;
 
4368
  struct ggml_tensor * ggml_cont(
4369
  struct ggml_context * ctx,
4370
  struct ggml_tensor * a) {
4371
+ return ggml_cont_impl(ctx, a);
 
 
 
 
 
 
4372
  }
4373
 
4374
  // make contiguous, with new shape
ggml.h CHANGED
@@ -1163,22 +1163,11 @@ extern "C" {
1163
  struct ggml_tensor * a,
1164
  struct ggml_tensor * b);
1165
 
1166
- // a -> b, in-place, return view(b)
1167
- GGML_API struct ggml_tensor * ggml_cpy_inplace(
1168
- struct ggml_context * ctx,
1169
- struct ggml_tensor * a,
1170
- struct ggml_tensor * b);
1171
-
1172
  // make contiguous
1173
  GGML_API struct ggml_tensor * ggml_cont(
1174
  struct ggml_context * ctx,
1175
  struct ggml_tensor * a);
1176
 
1177
- // make contiguous, in-place
1178
- GGML_API struct ggml_tensor * ggml_cont_inplace(
1179
- struct ggml_context * ctx,
1180
- struct ggml_tensor * a);
1181
-
1182
  // make contiguous, with new shape
1183
  GGML_API struct ggml_tensor * ggml_cont_1d(
1184
  struct ggml_context * ctx,
 
1163
  struct ggml_tensor * a,
1164
  struct ggml_tensor * b);
1165
 
 
 
 
 
 
 
1166
  // make contiguous
1167
  GGML_API struct ggml_tensor * ggml_cont(
1168
  struct ggml_context * ctx,
1169
  struct ggml_tensor * a);
1170
 
 
 
 
 
 
1171
  // make contiguous, with new shape
1172
  GGML_API struct ggml_tensor * ggml_cont_1d(
1173
  struct ggml_context * ctx,